Migrate ASP.NET Core Web API Project from 3.1 to 5

migrate asp.net core web api from 3.1 to 5

Last Updated on November 19, 2020 by Aram

It is very easy and straightforward to migrate ASP.NET Core Web API Project from 3.1 to 5.

In this tutorial we will be migrating the project that we built in our previous tutorial Secure ASP.NET Core Web API using API Key Authentication , this project was built using ASP.NET Core Web API 3.1.

Update Visual Studio

First things first; You need to have the latest update of Visual Studio 2019, which is now version 16.8.1

About Visual studio 2019 update version 16.81 - Migrate ASP.NET Core Web API Project from 3.1 to 5

If you don’t have the updated version, then you can simply select Help -> Check for Updates and from there Visual Studio will handle the rest of update work for you. Follow the installation steps and you should be ready.

You can always install the latest version of Visual Studio 2019 from Microsoft’s Visual Studio Website .

Backup your work

Next, just before you start with the migration, always make sure to take a backup of your latest code, either it was a local backup, cloud backup or committing and pushing your changes to some source control, in anyway, you always have to keep a clean copy from your latest work just in case you would need to revert to your old changes.

Changing Project Target Framework to .NET 5

Now once you are done from updating Visual Studio, open your solution again and from there right click on your project and choose properties:

Project properties

Then from the properties window, select the target .NET Framework and choose .NET 5.0

Project Properties, change Target Framework to 5.0 - Migrate ASP.NET Core Web API Project from 3.1 to 5

Once the change is applied, press ctrl + s to save your changes and close the properties window.

Now, the project’s target framework has been changed. Try to build the project and see if there are any errors raised, normally there shouldn’t be any.

Updating Project’s Dependencies

The next step here is to check if there are updates on your NuGet packages so that your project stays up-to-date with the latest framework version as well as your dependencies.

Right click on dependecies and choose manage NuGet Packages

Manage project dependencies

Then open the Update tab, there you will see the packages that are available for update for your project

update nuget packages - Migrate ASP.NET Core Web API Project from 3.1 to 5

As you can notice, in this project, we have references for 3 packages. We want to update all of them so all our libraries would be targeting the latest .NET framework 5 and benefiting from its great enhancements.

Check the ‘Select all packages’ checkbox and click update. Follow along with the update process and choose Ok and Accept for any dialogs that might popup.

Once this is done, rebuild your project or solution to double-check that there are no errors or warnings

Let’s do a quick peak view on the modified version of the project file to see what we have done on our project, if you are using a source control (like git or something else), it would be super easy to compare the changes on the file with the latest checked-in version

project file difference - Migrate ASP.NET Core Web API Project from 3.1 to 5
project file difference - Migrate ASP.NET Core Web API Project from 3.1 to 5

As you can notice, the TargetFramework is now net5.0 and even the dependencies versions are now 5.0.0, even though some other external dependencies versions might not be 5, but that shouldn’t matter, because the versioning of each package is done by the provider it is not imposed by the .NET Framework.

Testing with Postman

Now let’s run and test our application

Open postman and let’s see if the first API, login will work

Postman testing after migration - Migrate ASP.NET Core Web API Project from 3.1 to 5

Yes, it works.

Now let’s test the other endpoint, make sure to copy the response token value from the login endpoint and place it in the authorization header with Bearer prepended as the below

Postman testing after migration 2

And yes, that is working as well.

Deploying to IIS

If your application is already deployed to an IIS on some Windows Server, you just need to install the new hosting bundle for the ASP.NET Core Runtime 5.0.0 and then you should good to go.

If you are looking to do a fresh deploy of your migrated ASP.NET Core Web API 5, then you can just follow the rest of steps on my other tutorial Deploy ASP.NET Core Web Api on IIS , just skip the downloading part of the hosting bundle, since you have already downloaded the latest version.

Summary

Migrating from ASP.NET Core Web API 3.1 to 5 is an easy task with simple steps to follow. You should be good to go and face no problems at all. If you have doubts to update some external dependency, you can always verify the release notes or official website or GitHub account of the dependency provider for any compatibility or breaking changes or raised issues by other users.

If you want to get a step-by-step tutorial about how to secure your endpoints with JWT, then please check my previous article Secure ASP.NET Core Web API using JWT Authentication

Also if you want to apply API Key authentication to your Web API, then head to Secure ASP.NET Core Web API using API Key Authentication

Bonus

Have a great day, noon, evening, night wherever you are and enjoy this brilliant masterpiece for J.S.Bach – Goldberg Variations, BWV 988: Aria played by Lang Lang

One Comment on “Migrate ASP.NET Core Web API Project from 3.1 to 5”

Leave a Reply