Upgrade. NET Core 3.1 to. NET 8

Upgrade. NET Core 3.1 to. NET 8

NET Core 3.1 has been in use for a long time. In fact, Microsoft will no longer provide support at the end of 2022. The later LTS version. NET 6 will also expire support in November 2024, so upgrading directly to. NET 8 is the best choice.

最后更新 12/8/2023 5:27 AM
不止dotNET
预计阅读 5 分钟
分类
.NET
标签
.NET C# tech refresh

NET Core 3.1 has been in use for a long time. In fact, Microsoft will no longer provide support at the end of 2022. The later LTS version. NET 6 will also expire support in November 2024, so upgrading directly to. NET 8 is the best choice.

微软官方推出了升级工具:Upgrade Assistant

With the upgrade tool, upgrading becomes very simple. This article describes using the upgrade tool to upgrade a. NET Core 3.1 project to. NET 8.

Install the Upgrade Assistant

Make sure that VS 2022 has been upgraded to 17.8 first. Then install the extension in Extension Management of VS 2022:. NET Upgrade Assistant. Special attention is that if you have installed the Upgrade Tool extension before, you need to uninstall and reinstall it.

图片

upgrade project

In a solution for. NET Core 3.1, there will be many projects that will be upgraded one by one from the lowest level according to their dependencies.

  1. After installing the upgrade tool, right-click on the project and the Upgrade button will appear:

图片

  1. Select the upgrade method in the pop-up window:

图片

  1. Select the target version to upgrade. Here I choose. NET 8. This is a long-term supported version. The latest version of the upgrade tool only supports upgrades to 7 and 8. If you need to upgrade to. NET 6, you need to use the old version:

图片

  1. Select the content that needs to be updated, select all by default, and click "Upgrade selection" to upgrade:

图片

  1. You will soon see a prompt indicating that the upgrade was successful:

图片

compilation

I have verified several lower-version projects that no errors occurred during the upgrade process using the tool, but various problems occurred when code compilation was completed after the upgrade.

Question 1: Ionic.zip

In the original version, www.example.com was used for zip compression in the project. Now that.NET8 is no longer supported, you need to replace it with DotNetZip:

图片

Question 2: BinaryFormatter is outdated

Binary serialization is used in many places in the code, but BinaryFormatter has been deprecated in. NET8. There are two solutions:

  1. Modify the source code and replace it with a new recommended method.

  2. Modify the project file, ignore this problem, and add the following configuration to the project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
   ...
   <NoWarn>$(NoWarn);SYSLIB0011</NoWarn>
  </PropertyGroup>
</Project>

Reference: https://www.example.com

Question 3: Aspose usage issues

The Aspose suite is used to process Office files in the project. If the upgraded version has compatibility issues, it will be enough to upgrade to the corresponding version.

图片

Question 4: Method ambiguity

In previous versions, if List stored a complex type, there was no way to directly delete duplication according to a certain field in the type:

List<UserInfo> list = new List<UserInfo>();
list.Add(new UserInfo() { Name="oec2003",Age=18});
list.Add(new UserInfo() { Name = "oec2003" ,Age=18});
list.Add(new UserInfo() { Name = "oec2004" ,Age=18});
list.Add(new UserInfo() { Name = "oec2004" ,Age=18});

var distnctList = list.DistinctBy(x=>x.Age);

foreach (var item in distnctList)
{
    Console.WriteLine(item.Name);
}

public class UserInfo
{
    public string Name { get; set; }
    public int Age { get; set; }
}

The DistinctBy method in the above code is not available in. NET Core 3.1, so we extended a DistinctBy method. Unexpectedly, it was already provided by default in. NET8, which would lead to method conflicts. We just need to remove our extended method and use the default.

图片

run

After solving the above compilation problems, the program can start and run normally. The whole process is still very fast. I have to say that Microsoft's technology is very good for backward compatibility. Coupled with the support of tools, there is no pressure or burden to upgrade to the new version.

In contrast, although some other technologies are constantly updating and iterating, the mainstream still uses a specific version.

Keep Exploring

延伸阅读

更多文章
同分类 / 同标签 4/22/2026

Support for. NET by operating system versions (250707 update)

Use virtual machines and test machines to test the support of each version of the operating system for. NET. After installing the operating system, it is passed by measuring the corresponding running time of the installation and being able to run the Stardust Agent.

继续阅读
同分类 / 同标签 2/7/2026

Summary of experience in using AOT

From the very beginning of project creation, you should develop a good habit of conducting AOT release testing in a timely manner whenever new features are added or newer syntax is used.

继续阅读