In this article, we will discuss how to migrate applications from .Net Core 3.1 to .Net6.0. The .Net 6 has Long Term Support from microsoft for 3 years. It is the most recent release with long-term support. .NET Core 3.1 has already reached End of Support (EOF) in December 2022, and .NET 5 support ended in May 2022. This article describes how to upgrade the existing .Net application from .Net Core 3.1 to .NET 6.0 with an example of an ASP.NET Core Web API application and a .Net Core 3.1 class library project. Upgrading applications and class library project is almost similar. However, there is some difference between Upgrading ASP.NET Core Web app .Net 6.0 has been released with many new features and functionality. By implementing .Net 6 in the project, Your project will be faster than the previous version.
Pre-requisites:
To upgrade from ASP.NET Core 3.1 to .NET 6, you should have the below tools, SDK, and IDE.
Visual Studio 2022 | Link: https://visualstudio.microsoft.com/vs
.Net 6.0 SDK | Link: https://dotnet.microsoft.com/en-us/download/dotnet/6.0
Steps to Migrate or Upgrade from ASP.NET Core 3.1 to .NET 6.0 :
Follow the below steps to migrate your current ASP.NET Core 3.1-based application to .NET 6.0.
Step 1 - Change the Project Target Framework.
Open your current project in Visual Studio 2022. In the solution explorer, right-click on the Project name and choose Properties.
Step 2 – Select the Target framework to .NET 6.0 as shown below and save it.
After this step, the base framework changed. One can check or it’s alternatively changing the framework from the project_name.csproj file. The code looks similar to the code depicted below.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Extensions.Configuration.SystemsManager" Version="3.0.0" />
<PackageReference Include="AWSSDK.Core" Version="3.7.2.4" />
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.105.34" />
<PackageReference Include="AWSSDK.S3" Version="3.3.110.58" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.1" />
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="5.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.9" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="Images\" />
</ItemGroup>
</Project>
Step 3 - Updating Package references.
While migrating from ASP.NET Core 3.1 to
.NET 6.0 it is very important to upgrade the NuGet packages used in the current
project.
All you need to do is just click on the tools and then click on the “NuGet Package Manager” after that select “Manage Nuget Package for Solution”. Given below screenshot will help you to follow the steps.
Method 1:
You can change the package version to one that is compatible with .NET 6 by using NuGet Package Manager. Please use the image below as a guide.
As you can see in
the above image where currently we have some packages to update. But in the
case of your project package if there is any upgradation needed then you can
update it from mentioned above screenshot.
Method 2:
Upgrade the packages as mentioned below
by navigating to the Project.csproj file. All you need to do is just Click on
the Project name here is another way to update your package if there is needed
any upgradation. In the case of our project, there is some package for an update so we need to update it, As you can see in the mentioned below screenshot.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Extensions.Configuration.SystemsManager" Version="3.0.0" />
<PackageReference Include="AWSSDK.Core" Version="3.7.2.4" />
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.105.34" />
<PackageReference Include="AWSSDK.S3" Version="3.3.110.58" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.1" />
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="5.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.9" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="Images\" />
</ItemGroup>
</Project>
Step 4 - Delete Obj and bin folder.
In the case of our project, we have an existing package so we need to clear or remove the cache. In the case of your project, it may be necessary to remove the current bin and obj folders. Delete the directories by going to the project directory in concern. You can also remove the NuGet cache by using the command listed below.
dotnet nuget locals --clear all
Step 5 – Right-click on the project name in solution explorer and select Build. Your application should build successfully. On successful build of the application, your app is upgraded to .NET 6.0.
Conclusion:
A very simple project built on.NET Core 3.1 has been upgraded to the.NET 6 version. The complexity of your migration duties will depend on how many services, features, and libraries your older version used. There are more upgrade or migration stages as there are more libraries and functionalities. With the introduction of Asp.net Core 6.0, numerous new features and capabilities have been added. In this post, we go over various. NET-based application migration procedures from an earlier version to the most recent.NET 6. We appreciate any comments, questions, or feedback regarding this article.
I genuinely hope you enjoyed reading this article and found something useful. Comment below with your thoughts and recommendations.
Share This Post
Support Me