How to migrate ASP.NET core 3.1 to ASP.NET 6.0
ASP.NET 6.0 is a Long Term Support Version (supported for three years). The previous version, .NET Core 3.1 support will be finalized in December 2022, and support for .NET 5 will be ended May 2022. This article explains how to update an existing ASP.NET Core 3.1 project to ASP.NET Core 6.0.
Prerequisites
- Visual Studio 2022
- .Net 6.0 SDK
Following are the steps to migrate ASP.NET core 3.1 to ASP.NET 6.0:
- Update the target framework:
Open .csproj file in edit mode and change TargetFramework to .net6.0
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
- <TargetFramework>netcoreapp3.1</TargetFramework>
+ <TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project> - Upgrade package to 6.0 if required like:
<ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="3.1.6" />
- <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.6" />
- <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="3.1.6" />
- <PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
+ <PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="6.0.0" />
+ <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0" />
+ <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.0" />
+ <PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
</ItemGroup> - Delete bin and obj folders and clear cache:
We may need to delete the bin and obj folders. Run dotnet nuget locals --clear all to clear the NuGet package cache.
dotnet nuget locals --clear all
- Update Docker images:
- docker pull mcr.microsoft.com/dotnet/core/aspnet:3.1
+ docker pull mcr.microsoft.com/dotnet/aspnet:6.0Examples
-FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
+FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base-FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
+FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build - Minimal hosting model (OPTIONAL):
The minimal hosting model unifies Startup.cs and Program.cs into a single Program.cs file. ConfigureServices and Configure are no longer used. Apps migrating from ASP.NET Core 3.1 to 6.0 don't need to use the minimal hosting model, using Startup and the Generic Host used by the ASP.NET Core 3.1 templates is fully supported. To use Startup with the new minimal hosting model, see https://docs.microsoft.com/en-us/aspnet/core/migration/50-to-60-samples?view=aspnetcore-6.0 - Upgrade to common package which is build on .NET 6.0
- Build and run the project in VS 2022 and verify the bin folder, it should contain only .net6.0 libraries.
References
2 Comments
Blog
Active User (0)
No Active User!
great..
Rashmi
08-Aug-2022 at 04:01