How to Upgrade ASP.NET Core 2.2 to .NET Core 3.1 LTS
by Mauricio Rojas, on Dec 12, 2019 7:17:45 AM
Step 1 - Upgrade to .NET Core 3.1 LTS
Ok. So the first thing is to edit the csproj file:
Step 2 - Change Startup Configuration
Next, you need to update public void Configure(IApplicationBuilder app, IHostingEnvironment env) to public void Configure(IApplicationBuilder app,IWebHostEnvironment env). IHostingEnviroment was deprecated.
I think the biggest change when upgrading AP.NET Core to 3.1 is related to setting up your routes with the AddMVC.
For example, Iin ASPNet Core 2.2 you could write:
But on .NET Core 3.1 you have to adjust that code to something like this:
All of the configuration steps are detailed in the microsoft docs for upgrading to .NET Core 3.0
Step 3 - Add Health Check Support
The MapHealthCheck is not mandatory. I just think is a good practice to add Health Check Support
Next a minor change: add the using Microsoft.Extensions.Hosting; this is necessary to allow the IsDevelopment extension method to work.
Step 4 - Test Your Update
At this point everything is compiled so I gave it a try, but I got a nasty exception:
System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.
Oh wow!! It seems this is a change related to this ASP .NET Core Issue
But that is easy to fix.
You just add at the end of the ConfigureServices these lines:
And... you are done!.
Last Step. Run the upgraded app on .NET Core 3.1
You can check out the code on our github repo.
The Hanselman blog post I mentioned earlier goes deep into other interesting stuff like publishing to azure and using side loading.
Check his post. He is really wise guy.