WinForms Migration First Steps
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.
To start with the migration process, please proceed with the following steps:
Unload the Project
Delete the content of the .csproj file
Copy the following text into the .csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>net48;net6.0</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<EmbeddedResourceUseDependentUponConvention>true</EmbeddedResourceUseDependentUponConvention>
<RootNamespace>$(MSBuildProjectName.Replace(" ", "_").Replace("-", "_"))</RootNamespace>
<NoWarn>CA1416</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))'=='net'">
<OutputPath>bin\</OutputPath>
<StartupObject></StartupObject>
<OutputType>Library</OutputType>
<RunCommand>$(ProgramFiles)\IIS Express\iisexpress.exe</RunCommand>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RunArguments>/path:"$(MSBuildProjectDirectory)" /port:5000</RunArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))'!='net'">
<StartupObject>$(RootNamespace).Startup</StartupObject>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))'=='net'">
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Windows.Forms"><Aliases>swf</Aliases></Reference>
<Reference Include="System.Data.DataSetExtensions" />
<Compile Remove="Startup.cs" />
<Content Include="Startup.cs"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Themes\" />
</ItemGroup>
<ItemGroup>
<Content Update="Default.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<Content Update="Web.config">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Remove="Default.html" />
<None Remove="favicon.ico" />
</ItemGroup>
<ItemGroup>
<Content Include="Default.html">
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
</Content>
<Content Include="favicon.ico">
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Wisej-3" Version="3.0.*" />
<PackageReference Include="System.Data.SqlClient" Version="4.*" />
</ItemGroup>
</Project>
4. Add a Startup.cs or Startup.vb file to your project
5. Add the following text into Startup.cs / Startup.vb
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Wisej.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>
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
Args = args,
WebRootPath = "./"
});
var app = builder.Build();
app.UseWisej();
app.UseFileServer();
app.Run();
}
}
}
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.
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.
3. Add the configuration files to the project. You will need the following files: a. Default.html b. Default.json c. Web.config
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.
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
5. You´re done. Congratulations. You should now be able to run your Wisje web application.
Last updated
Was this helpful?