Migrating your API from .NET Core 3.1 to .NET 6: Explained More Easily
Note: The more comprehensive guide is listed on Microsoft Official Guide. This Guide explains briefly what you will need and how to migrate easily.
Microsoft officially ended support for .NET Core 3.1 since 13 December 2022, this means even though any application running using the framework will still works, you will no longer receive updates for the framework (Which may pose security issue!). If you are building a new app, consider using the new .NET 6 Framework by Microsoft instead.
Why .NET 6? There’s .NET 7
From the image above, you can see .NET 7 is a STS (Short Term Support), you can always go for .NET 7 instead to experience the newest stack available right now, but most would argue that .NET 6 is already sufficient for their application, and with the framework being a LTS (Long Term Support), you’ll be guaranteed that .NET 6 will not be obsolete within the next 3 years.
What will you need?
- Visual Studio 2022 (with Integrated .NET 6 support), OR
- any other IDE and install the .NET 6 SDK
On your Visual Studio Installer, modify your installed Visual Studio, and go to the “Individual components” > “.NET” > “.NET 6.0 Runtime (LTS)”
Make sure during the installation, the .NET 6.0 Runtime are highlighted to make sure you installed the SDK correctly.
After that, on your API, update your .csproj file so it targets the new net6.0 Framework
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>
Furthermore, if you have any Packages that .NET use such as Microsoft.AspNetCore.*, Microsoft.EntityFrameworkCore.*, Microsoft.Extensions.*, System.Net.Http.Json, make sure the version used are 6.0.0 or later! Some libraries are also not supported or might behave differently, you can see more at the official documentation: Breaking changes in .NET 6 — .NET | Microsoft Learn
And that’s it! Your API should now use the new .NET 6 Framework.