Migrating to .NET Core 2.0

If you have projects in the in .NET Core 1.1

In previous posts we created a .NET Core App from scratch and used scaffolding tools for bootstrapping the project. In these posts we used projects in .NET Core 1.1. For future posts we are going to use projects in the new version of .NET Core, .Net Core 2.0 has various improvements, the most significant changes are listed in this Microsoft doc.

Let’s do it!

In this post we are going to show how to migrate from .NET Core 1.1 to .NET Core 2.0. First, to change the .NET Core version in an existing project in 1.1 we need to change the following files:

Project.csproj

We are going to remove all the Microsoft.AspNetCore references and add just one reference called Microsoft.AspNetCore.All and update the rest of the versions references. We can see this in the following example:

In .NET Core 1.1:

In .NET Core 2.0:

Program.cs

In the Program.cs we are going to simplify the Main code, and add a static method to build the web host. We can see this in the following example:

In .NET Core 1.1:

In .NET Core 2.0:

Startup.cs

This file is cleaner in the constructor method and changes the IConfigurationRoot attribute by IConfiguration. We can see this in the following example:

In .NET Core 1.1:

In .NET Core 2.0:

Congratulations!

You already have your .NET Core application running in the 2.0 version. In the next post, we are going to see how use Entity Framework to persisting data in .NET Core.