# Update Existing Projects

Wisej.NET 3 introduces a new approach for creating and working with projects based on ASP.NET Core. The changes include a new [SDK Project Format](https://docs.microsoft.com/en-us/dotnet/core/project-sdk/overview), Kestrel Web Server, and more.

{% hint style="success" %}
**There is no need to change the project format if you are staying with .NET 4.8!** Wisej.NET 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.
{% endhint %}

## The Basics

### **Change Project Format to SDK**

{% hint style="danger" %}
When migrating a Wisej.NET **2.x** project to Wisej.NET **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.
{% endhint %}

Moving from older versions of Wisej.NET to Wisej.NET 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.

{% tabs %}
{% tab title="C#" %}

```xml
<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>

```

{% endtab %}

{% tab title="VB.NET" %}

```xml
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFrameworks>net48;net6.0</TargetFrameworks>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <EmbeddedResourceUseDependentUponConvention>true</EmbeddedResourceUseDependentUponConvention>
  </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" />
    <Compile Remove="Startup.vb" />
    <Content Include="Startup.vb"/>
  </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>
    <PackageReference Include="Wisej-3" Version="3.*" />
  </ItemGroup>

</Project>
```

{% endtab %}
{% endtabs %}

5\. **Reload** the Project

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

{% hint style="danger" %}
Files that are **Embedded Resources** are reset to Content, don't forget to set them again to Embedded Resource.
{% endhint %}

### 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".

<div align="left"><img src="https://553579532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MF1D11gPs_az3xaKusw%2Fuploads%2FKqTemLdUXsKR5HYv4YHI%2Fimage.png?alt=media&#x26;token=f420008c-6f7a-4db9-a908-05f6a2adad6c" alt=""></div>

{% hint style="info" %}
It's likely that your projects don't have any Wisej.Framework reference in the .resx files.
{% endhint %}

### Add Startup.cs

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

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.

{% file src="<https://553579532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MF1D11gPs_az3xaKusw%2Fuploads%2FERruLM6ql0VvRCJYa7Ic%2FStartup.cs?alt=media&token=5f76f8d5-542d-4ad2-bc09-c16d916ff9ad>" %}

{% file src="<https://553579532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MF1D11gPs_az3xaKusw%2Fuploads%2FnghL09tZQoqf5fDwRMaC%2FStartup.vb?alt=media&token=cb1c8fd3-bd41-4765-bfc4-2a1da5c224a6>" %}

{% tabs %}
{% tab title="C# Startup.cs" %}

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

{% endtab %}

{% tab title="VB.NET Startup.vb" %}

```visual-basic
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

```

{% endtab %}
{% endtabs %}

{% hint style="danger" %}
Don't forget to update the **Namespace**.
{% endhint %}

### Add launchSettings.json

Wisej 3 projects targeted for .NET Core 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.

{% file src="<https://553579532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MF1D11gPs_az3xaKusw%2Fuploads%2F0ob9iL89Q9Tg1T98cLcz%2FlaunchSettings.json?alt=media&token=6751826f-1887-466c-a7d4-26b14b7aec04>" %}

{% code title="launchSettings.json" %}

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

{% endcode %}

{% hint style="info" %}
**Profiles** define the startup behavior for the application. Don't forget to update the profile names.
{% endhint %}

## 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:

* [GenerateAssemblyInfo ](https://docs.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props)= false
* [EmbeddedResourceUseDependentUponConvention](https://docs.microsoft.com/en-us/dotnet/core/compatibility/msbuild) = true
* [AppendTargetFrameworkToOutputPath ](https://docs.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props)= false (.NET Framework)
* [OutputPath ](https://docs.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-properties?view=vs-2022)= bin/ (.NET Framework)

## Implementation Changes

With the release of Wisej.NET 3.0, which is the first version to support both .NET Framework and .NET Core, we have standardized all classes to ensure compatibility across these two environments. This means that any class differences between the two have been reconciled, and unique classes from either environment have been seamlessly integrated.

### UITypeEditor

Originally, the class `System.Drawing.Design.UITypeEditor` was utilized. However, because it does not exist in .NET Core, we have reimplemented it as `Wisej.Web.UITypeEditor`.&#x20;

Therefore, attributes that were previously declared as `[Editor(typeof(MyEditor), typeof(System.Drawing.Design.UITypeEditor))]` must be updated. You can now specify them as `[Editor(typeof(MyEditor), typeof(UITypeEditor))]` or `[Editor(typeof(MyEditor), typeof(Wisej.Web.UITypeEditor))]`, depending on the namespaces defined in your using directives.

### Http\* Types

Previously, all `Http*` types were located in the `System.Web` namespace. However, in .NET Core, these types differ significantly. To address this, we have reimplemented a unified `Http` type system under `Wisej.Core.Http*`. This ensures consistency and compatibility when working across different .NET environments.

When transitioning from `System.Web` classes, you will likely encounter compilation errors, making it straightforward to identify where these classes are used in your code. Typically, these classes are utilized in the Upload control, within any implementation of the `IWisejHandler` interface, and in managing cookies collections. Identifying and updating these areas will be essential to ensure compatibility with the new system.
