How To Migrate Your .Net 5 Application To .Net 6?

ManekTech
4 min readOct 18, 2022

--

Dot net five was welcomed across the developer community with open hands as it was one .NET framework capable of replacing .Net Core, .Net Framework, and Xamarin. It offered the developers all the modern code and APIs for application development. Besides expanding the .NET capabilities, it provided a single .NET runtime framework with uniform runtime behavior for developing every kind of application.

What is .NET 6?

.NET 6 was released in November 2021. It can be used for .net development across different OS, including Windows, macOS, and Linux. In addition, it gets native support from the Arm-based windows operating system along with M1 Apple silicone chips. The .net developer community is excited to use this version as it can be used to develop different applications, including web applications, mobile apps, desktop apps, and games.

It becomes essential to update the last releases with new releases as the older versions can go out of support. If you have an application in .NET 5, you can hire a .NET developer and migrate the application to .NET 6. The process will be simple with the basic .Net Framework present in the system. Below are the steps to migrate your .NET 5 application to .NET 6.

1. Install the JDK

For migrating the .NET 5 applications to .NET 6, we need to have the JDK of the latter. Install the .NET 6 JDK on the system. This JDK will equip you with all the tools required to develop any application in .NET 6. After installation, check the version. You can enter the command given below for the same:

dotnet –version

2. Update Target Framework

You have to update the target .NET framework with the latest version. First, check the target framework moniker of your web app. You will get the information about the .NET runtime you need to use. Next, open the project XML file in your application to find the target framework. This application project file contains the TargetFramework moniker. It is located under the PropertyGroup tag.

<PropertyGroup>
<! — <TargetFramework>net5.0</TargetFramework> →
<TargetFramework>net6.0</TargetFramework>

<UserSecretsId>xxx33795–1b05-xxxx-926f-dcc112c2xxxd</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

3. Update Package References

You need to update the NuGet package dependencies from .NET 6. You can also call them application package references. Updating these dependencies will help you implement the dependency injection. You can locate the .csproj file, which is located under the <ItemGroup> tag, to find the NuGet package references. The package size is not uniform for every application. It increases with the size and complexity of the application.

Check the first number in the NuGet package version to find the performance of the target .NET framework. When you update, ensure all the packages are updated to the target framework.

<ItemGroup>
<! — <PackageReference Include=”Microsoft.AspNetCore.Authentication.JwtBearer” Version=”5.0.13" /> →
<! — <PackageReference Include=”Microsoft.EntityFrameworkCore.Design” Version=”5.0.9"> →
<PackageReference Include=”Microsoft.AspNetCore.Authentication.JwtBearer” Version=”6.0.3" />
<PackageReference Include=”Microsoft.EntityFrameworkCore.Design” Version=”6.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<! — <PackageReference Include=”Microsoft.EntityFrameworkCore.SqlServer” Version=”5.0.9" /> →
<! — <PackageReference Include=”Microsoft.VisualStudio.Web.CodeGeneration.Design” Version=”5.0.2" /> →
<! — <PackageReference Include=”Swashbuckle.AspNetCore” Version=”5.6.3" /> →
<PackageReference Include=”Microsoft.EntityFrameworkCore.SqlServer” Version=”6.0.3" />
<PackageReference Include=”Microsoft.VisualStudio.Web.CodeGeneration.Design” Version=”6.0.2" />
<PackageReference Include=”Swashbuckle.AspNetCore” Version=”6.3.0" />
</ItemGroup>

4. Update Debug Directory

Many developers use the VS code for application development. In this case, you have to update the launch.json file with the line given below:

Source: https://www.makeuseof.com/dotnet-5-6-application-migrate/

5. Check if You Need the Minimal Hosting Model

. NET 6 has introduced the minimal hosting approach. You will not find a startup.cs file in the.NET6 applications. Program.cs file is used for application bootstrapping and service configuration. It is not a compulsion to update all the old applications to .NET 6. However, it would help if you thought about it in the future. You can refer to the codes below to migrate from the startup class to Program. cs.

.NET 5 startup class

.NET 5 Program.cs

Now, we can see the .NET 6 Program.cs

source: https://dev.to/moe23/upgrade-net-5-to-net-6-n2c

Conclusion

These are some simple steps to migrate any .NET 5 applications to .NET 6. This .NET 6 version can be said to be the fastest full-stack web framework that can enhance your application’s productivity and performance. You get many new components with .NET 6, including new git tooling and robust diagnostics.

In addition, the development gets simplified with lowered computing costs. If you are still using .NET 5, it is high time to transition. Hire a .NET developer today to update your system with .NET 6 and migrate your application to the latest version to leverage the new capabilities of the .NET framework.

--

--

ManekTech

I am Olivia, I would love to write about the Technology, Trends, News. https://www.manektech.com/