dotNET Core Update from 3.1 to 6
Migrate ASP.NET Core Razor Project
In this paragraph, we will update the ASP.NET Core project from 3.1 to 6.
The following table shows that current LTS version status:
LTS Version | Release Date | EOS |
---|---|---|
.NET Core 2.1 | 2018-05-30 | 2021-08-21 |
.NET Core 3.1 | 2019-12-03 | 2020-12-13 |
.NET 6 | 2021-11-08 | 2024-11-12 |
.NET 8 | 2023-11 (projected) | 2026-12 (projected) |
Modify .csproj
The main topics in this step are:
- Change the target framework from
.NET Core 3.1
to.NET 6.0
. - Update the NuGet packages (Microsoft.AspNetCore.*, Microsoft.EntityFrameworkCore.*, Microsoft.Extensions.*, and System.Net.Http.Json).
1 | <PropertyGroup> |
Modify Program.cs
In this step, we need to merge Startup.cs
into Program.cs
, the common rules as following table:
.NET Core 3.1 | .NET 6 |
---|---|
configuration | builder.Configuration |
services | builder.Services |
env | app.Environment |
A basic example of Program.cs
:
1 | var builder = WebApplication.CreateBuilder(args); |
After merged, we can remove the Startup.cs
from current project.
Migrate Ubuntu Runtime
Steps
Check the dotnet runtime
1 | # If is SDK |
(Optional) Remove .NET Core Previous Versions
Remove all version
1
2$ sudo apt -y remove dotnet-host
$ sudo apt -y autoremoveRemove specific SDK version
1
$ sudo apt -y remove dotnet-sdk-3.1
Remove specific runtime version
1
2$ sudo apt -y remove dotnet-runtime-3.1
$ sudo apt -y remove aspnetcore-runtime-3.1
Install .NET 6
The .NET SDK allows you to develop apps with .NET. If you install the .NET SDK, you don’t need to install the corresponding runtime.
1
2$ sudo apt update
$ sudo apt -y install dotnet6The ASP.NET Core Runtime allows you to run apps that were made with .NET that didn’t provide the runtime.
1
2$ sudo apt update
$ sudo apt -y install aspnetcore-runtime-6.0As an alternative to the ASP.NET Core Runtime, you can install the .NET Runtime, which doesn’t include ASP.NET Core support.
1
2$ sudo apt update
$ sudo apt -y install dotnet-runtime-6.0