Disappointed, I upgraded .NET Core3.1 to .NET5 overnight, and it felt like a pit!

11 November 11 is the day of e-commerce carnival and the day when .NET5 is officially released. My wife is waiting for the zero-point spike, but I am refreshing the Microsoft official website and waiting for updates, and then I start tossing for the first time. Previously, Scott Hunter vowed in his blog to smoothly migrate .NET Core3.1 to .NET5, so he went to upgrade my treasure project on the same day. The result was that there were no big pits and small pits. It took a day to get it done. Now let’s take a closer look. Provide a point of reference for the construction.

Background introduction

The upgraded project was previously open sourced on Github, and 300 stars were added a week. Although it was closed for some reason, I personally took it very hard. This is not. NET5 has just been released, the upgrade began the first time.

The project is a WeChat applet mall. The backend is supported by the microservice architecture. Ocelot gateway + Consul service registration discovery + Core WebApi + gRPC + IdentityServer4 are all arranged, and the overall is still relatively complicated. MongoDB, Redis , RabbitMQ are also arranged, and then in the process of .NET Core3.1 upgrade .NET5, various pits.

VS upgrade pit

The first pit of the upgrade comes from the VS tool upgrade! Previously, the .NET5 preview version, RC1 and RC2 used Visual Studio 2019 Preview. At this moment, the official version of .NET5 found that only Visual Studio 2019 needs to be upgraded to V16.8, and then it was upgraded enthusiastically. A hit: Visual Studio Installer prompts that the network is not connected and cannot download! Of course it’s not my network problem. In fact, it’s a problem with DNS resolution (some users will encounter, the solution is to set the computer’s DNS to 8.8.8.8), but after all, it was the early morning of the 11th and thought it was an official Microsoft The synchronization was not enough, I chose to change the tool, went directly to Linux to upgrade with VS Code, and then started the second wave of environmental pits!

**Experience: **If you encounter the Visual Studio Installer prompting that the network is not connected and unable to download, you can set the current computer DNS to 8.8.8.8.

Linux environment pit

Before the development of VS Code in the Linux environment, I was quite familiar with it. This time I was thinking about upgrading .NET5, so I conveniently changed the Linux system from CentOS7 to CentOS8, and then there were gorgeous pits. For example, the name of the network card in CentOS8 has changed from ens33 to eth0, and nftables is used to replace iptables. Various small changes are hard to prevent. Then the latest version of docker has some small changes from the previous commands, which caused various failures of the Linux+Docker operation notes that were organized before. , Tossing back and forth for several hours.

Of course, the environment is just the environment, and it will pass after the toss. The pits at the code migration level are the most troublesome, because I don’t know how many have not been discovered!

. NET5 migration pit pit

It is very easy to upgrade the project from .NET Core3.1 to .NET5. Upgrade the SDK version from 3.1 to 5.0 in global.json, and then change the TargetFramework from netcoreapp3.1 to net5.0. There are also some class library namespace changes that are completely okay. The smart prompt of the first IDE in the universe can be easily solved. However, in the process of real project migration, I encountered various small problems:

1

Swagger is integrated by default in the Core WebApi framework template project. This is a new addition, but the previous project had some custom configurations and extensions, which also caused conflicts.

2

The third-party framework version of IdentityServer4 has been upgraded. There are a lot of API changes, and a lot of code cannot be changed. Although this pot is not .NET5, it is also encountered in the upgrade project.

3

It took some time to try C#9, and I wanted to experience the new features of the new syntax, such as Native ints, Pattern matching improvements, and pattern matching improvements, but I got into it several times.

4

The bug found after the project upgrade, the value of DateTime has changed every day. In ASP.NET Core 3.1 and earlier, DateTime is bound to server local time, and after 5.0, DateTime is bound to UTCTime.

Come to the .NET5 project migration battle

I don't know if I don't do it. It's unreliable to rely on reading posts. Self-proclaimed as an old driver, it took almost 10 hours to complete the migration of the project, and I don’t know if there are any hidden pits! Everyone is currently facing the migration of projects to .NET5, and these pit experiences are also rare. At 8 o'clock tonight, I will give you a live broadcast to share, practice .NET5 + microservices + applets, complete the first wave of .NET5 combat, scan the code to enter the group, see you tonight!

Supporting preparation

For this sharing, you only need to prepare the .NET5 related environment in advance. The community, professional, and enterprise version installation files of VS2019 16.8 are packaged here, as well as the corresponding activation code. Please get it if you need it.

Scan the QR code to receive supporting information

Recommended Posts

Disappointed, I upgraded .NET Core3.1 to .NET5 overnight, and it felt like a pit!