Loading...

Upgrade To DotNet 5 Dead Easy

Published
04-12-2020

Introduction

I have a policy about my applications - No legacy code! So now that Dotnet 5 has arrived I have started upgrading all my sites to use it. Also, since I run all my sites on Azure I will then publish them to Azure.

Thankfully DotNet 5 is available from Day 0 on Azure. Interestingly, Microsoft have said that from now on when a DotNet release is made GA, it will be available on Azure from Day 0.

I have done three Azure App Services (two Web Apps and one Web API involving several class libraries which were also upgraded) and there were no breaking changes. The upgrade was from DotNet Core 3.1 so you would expect it to be relatively easy, however I have never upgraded any application before without something breaking. So this is impressive.

Upgrading

The first step to upgrade a project is to right mouse click on the project, select the Application tab and change the Target Framework to .Net 5:

 

In one of my projects I was unable to do that as there was a blank in the Target Framework drop down box. In that case you need to edit the csproj file directly (right mouse click on the project and select Edit Project. Edit the TargetFramework tag so that it contains the following:


        net5.0

You can then use the Nuget Package Manager to upgrade any packages that have .Net 5 versions.  

Publish Settings

Firstly you need to change the Target Framework in your publish settings (if you already have them):

Right mouse click on the project and click Publish.

Click on Edit and change the following setting on the Settings Tab:

error message you will probably get when you publish

If you try to publish to Azure, and I suspect other places as well, you will probably get the following error message:

project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.1

If you have changed the TargetFramework in the Publish Settings and also changed it in the Build configurations (as described above) and you are still receiving this message, you will have to delete the contents of the bin and the obj folders.

Publishing to Azure

At the moment you will probably have to manually upgrade the version of DotNet in the Azure Portal to DotNet5 in order to successfully publish from Visual Studio. Note that Microsoft have dropped the .Net Core and .Net 5 is just version 5 of .Net rather than version 5 of .Net Core. If you don't make the change in the Portal first, you will probably get the above error message when the publish command runs. Below are the settings you need to change in the Azure Portal (Configuration - General Settings Tab):

All the best.


Latest posts