Update Existing Projects

Wisej 3 introduces a new approach for creating and working with projects based on ASP.NET Core. The changes include a new SDK Project Format, Kestrel Web Server, and more.

There is no need to change the project format if you are staying with .NET 4.8! Wisej 3 supports both .NET Framework and .NET Core. You only need to change the project format to the SDK format if you are going to use .NET Core and ASP.NET Core.

The Basics

Change Project Format to SDK

When migrating a Wisej 2.x project to Wisej 3, it's not recommended to change the existing project but rather create a new Wisej project using the new templates and copy over files.

Moving from older versions of Wisej to Wisej 3 requires updating the project to the new SDK Project format.

  1. Take note of all embedded resources, references and build customizations within the Project.

  2. Unload the Project.

  3. Delete the content of the .csproj file.

  4. 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>

5. Reload the Project

6. Add embedded resources, references, and build customizations back.

Files that are Embedded Resources are reset to Content, don't forget to set them again to Embedded Resource.

Upgrade Resource Files (.resx)

All the localization .resx files need to be upgraded to Wisej.Framework, Version=3.0.0.0. It's a simple task that can be completed using Visual Studio Search & Replace.

Replace "Wisej.Framework, Version=2.0.0.0" with "Wisej.Framework, Version=3.0.0.0".

It's likely that your projects don't have any Wisej.Framework reference in the .resx files.

Add Startup.cs

A Startup.cs file is required for ASP.NET Core projects (Wisej projects targeting .NET 6+).

  1. Right-Click the Project.

  2. Click Add > Class.

  3. Set the name to Startup.cs.

  4. Click Add.

  5. Copy the following content into the Startup.cs file or download the file below.

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();
		}
	}
}

Don't forget to update the Namespace.

Add launchSettings.json

Wisej 3 projects targeted for .NET 6+ require adding a launchSettings.json file to the /Properties directory of the project.

  1. Right-Click the project on the \Properties folder ⚠️.

  2. Click Add > New Item > JSON File.

  3. Name the file launchSettings.json.

  4. Copy the following text into the file.

launchSettings.json
{
    "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
            "applicationUrl": "http://localhost:54429",
            "sslPort": 0
        }
    },
    "profiles": {
        "MyProjectName": {
            "commandName": "Project",
            "launchBrowser": true,
            "applicationUrl": "http://localhost:5000"
        }
    }
}

Profiles define the startup behavior for the application. Don't forget to update the profile names.

Project Properties

The new SDK project format has many properties that are not available in the project property panel. You have to get used to editing the .csproj or .vbproj files directly.

Unfortunately, there isn't a comprehensive list anywhere and many properties are not standard and depend on build targets. All you can do is search around...

These are just a few that we have added to our templates:

Last updated