The following steps describe a basic migration of a Desktop WinForms application to a Web Application based on Wisej.NET.
With Wisej.NET, it's so much easier to migrate your existing WinForms application to a full fledged Web Application.
To do so, we have prepared this checklist to guide you through the process.
Make sure to install Wisej.NET's VSIX package from Wisej.NET Build page
Take note of all embedded resources, references and build customizations within the Project
Make sure that you have a backup ready of your application before proceeding with the migration process to prevent loss of critical data or source code.
From this point, you can choose one of two options to migrate your solution, either upgrading to the New Project SDK Format or staying with the current Project Format.
New Project SDK Format
Starting with Wisej.NET 3, we started supporting .NET 6.
This enabled Wisej.NET to be cross-platform, and added many more features like Dependency Injection, running in a Docker Container, and much more.
You can read about everything new in Wisej.NET from HERE.
To start with the migration process, please proceed with the following steps:
Make sure to add the missing project references, missing packages and/or assemblies
Make sure to include .NET Framework 4.8 (net48) in your TargetFrameworks parameter since it's needed for the designer. You can ommit .NET 6 (net6) if you have compatibility issues.
4. Add a Startup.cs or Startup.vb file to your project
5. Add the following text into Startup.cs / Startup.vb
usingMicrosoft.AspNetCore.Builder;usingMicrosoft.Extensions.Configuration;usingWisej.Core;namespace $safeprojectname${ /// <summary> /// The Startup class configures services and the app's request pipeline. /// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940. /// </summary>publicclassStartup {publicStartup(IConfiguration configuration) { Configuration = configuration; }publicIConfiguration Configuration { get; }publicstaticvoidMain(string[] args) {var builder =WebApplication.CreateBuilder(newWebApplicationOptions { Args = args, WebRootPath ="./" });var app =builder.Build();app.UseWisej();app.UseFileServer();app.Run(); } }}
Imports Microsoft.AspNetCore.Builder
Imports Microsoft.AspNetCore.Hosting
Imports Microsoft.Extensions.Configuration
Imports Microsoft.Extensions.DependencyInjection
Imports Microsoft.Extensions.Hosting
Imports Wisej.Core
''' <summary>
''' The Startup class configures services and the app's request pipeline.
''' For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940.
''' </summary>
Public Class Startup
Public Sub New(configuration As IConfiguration)
Me.Configuration = configuration
End Sub
Public ReadOnly Property Configuration As IConfiguration
Public Shared Sub Main(args As String())
Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(
Sub(builder)
builder.UseWebRoot("./")
builder.UseStartup(Of Startup)()
End Sub).Build().Run()
End Sub
'' This method gets called by the runtime. Use this method to add services to the container.
Public Sub ConfigureServices(services As IServiceCollection)
End Sub
'' This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Public Sub Configure(app As IApplicationBuilder, env As IWebHostEnvironment)
app.UseWisej()
app.UseFileServer()
End Sub
End Class
Do not forget to update your Namespace
Old Project Format
You can create a new Wisej.NET project and copy over all the files from the original Win-Forms application.
If you choose this approach then you can skip steps 1, 2 and 3 as the assemblies and the configuration files will be added automatically.
Or you can edit your existing WinForms project file and make the following changes:
1. Change the settings of the existing project. You can do this by editing the .csproj file in a text editor and make the following changes
- Add the project type GUIDs under the ProjectGuid node:
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
- Change the OutputType from WinExe to Library
- Add the import nodes for the web applications under the main Project node:
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
Summary of changes:
2. Open the WinForms solution and add Wisej.NET's NuGet Package.
Make sure to check the target .NET framework version as it has to be .NET Framework 4.8 or you'll get errors upon installing the NuGet Package.
3. Add the configuration files to the project. You will need the following files:
a. Default.html
b. Default.json
c. Web.config
All these files are generated by default when creating a new Wisej.NET project, so you can simply copy them over from a new project. You can find a detailed explanation of these here: http://wisej.com/docs/html/Configuration.htm
You might also want to adjust the Title in default.html to match with your migrated project.
Replacing WinForms Namespaces with Wisej.NET
1. Replace all occurrences of System.Windows.Forms with Wisej.Web
2. Build the application and resolve the compiler errors: in most of the cases you will get compiler errors due to some missing properties and/or methods that are obso-lete in Wisej. You can simply comment out these.
If you find many similiar code lines to clean up, regular expressions in Visual Studio Replace can come in quite handy.
Use for example .*UseVisualStyleBackColor.*\n to remove all those lines as they are not needed anymore.
3. Change the Main method; in a typical WinForms application you probably had something like this in the Main method:
The first two lines can be commented out as they are not needed in a web appli-cation. The third one has to be changed to show instead the Login dialog:
3. Change the startup method in the Default.json file to the Main method from Pro-gram.cs:
4. Check the Output Path. It should just be \Bin. If it´s \Bin\Debug please change it to \Bin
If you have been using ConnectionStrings in App.Config, copy them over to Web.Config.
(in configuration section).
5. You´re done. Congratulations. You should now be able to run your Wisje web application.