Contact Application - Upgrade ASP.NET Core 2.0 To 2.1

In this article, we will look into steps for a contact application - upgrade ASP.NET Core 2.0 to 2.1. Please see my previous articles about how we developed a contact application.

  1. Contact Application using ASP.NET Core Web API, Angular 6.0, and Visual Studio Code Part One
    In the article, we will set up an ASP.NET Core Web API project and develop the Web API for contacting CRUD operations.

  2. Contact Application using ASP.NET Core Web API, Angular 6.0, and Visual Studio Code Part Two
    In the article, we will set up Angular 6 within ASP.NET Core Web API Project, and develop the contact form & list component using Angular Material UI that will consume Web API which we have created in Part One.

  3. Contact Application Azure Deployment
    In this article, we are going to deploy/host a contact application with Visual Studio Code to Azure Web Apps.

Please note

Previously, we used ASP.NET Core 2.0.3 for contact applications. Now, let us upgrade to ASP.NET Core 2.1.5.

This is the download link for .NET Core where you can find the appropriate version of the SDK and Runtime. I have installed .NET Core 2.1.5.

Please see What's new in ASP.NET Core 2.1 to know the new features of ASP.NET Core 2.1.

Let’s start the upgrading process.

  • Go to the root folder of the "contact-app" project. Open ‘contact-app.csproj’ file.

    Contact Application - Upgrade ASP.NET Core 2.0 To 2.1
  • Now, change the target framework to .NET Core 2.1.

    <TargetFramework>netcoreapp2.1</TargetFramework>
  • Replace the package reference for ‘Microsoft.AspNetCore.All’ with a package reference for ‘Microsoft.AspNetCore.App’ and remove the ‘Version’ attributes on the package reference to ‘Microsoft.AspNetCore.App’. Then, set ‘Version’ to 2.1.4 for other package reference.

  • Please refer to this link for more details of ‘Microsoft.AspNetCore.All’ & ‘Microsoft.AspNetCore.App’ meta package.

  • Remove references to <DotNetCliToolReference> elements.
  • Save ‘contact-app.csproj’ file and final ‘contact-app.csproj’ file will look like the below screenshot.

    Contact Application - Upgrade ASP.NET Core 2.0 To 2.1

Now, restore the project by entering the following command: "dotnet restore".

Contact Application - Upgrade ASP.NET Core 2.0 To 2.1

Change the main program

In .NET Core 2.1, the main part is to replace the call to ‘BuildWebHost’ with CreateWebHostBuilder. IWebHostBuilder was added to support a new integration test infrastructure.

So, we have updated “IWebHostBuilder“ in the program.cs file as shown below.

  1. public class Program {  
  2.     public static void Main(string[] args) {  
  3.         CreateWebHostBuilder(args).Build().Run();  
  4.     }  
  5.     public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args).UseStartup < Startup > ();  
  6. }  

Our application is now upgraded into ASP.NET Core 2.1. We can run the application by dotnet run and verify the functionality.

Conclusion

This is how we can upgrade our ASP.NET Core 2.0 application to 2.1. You can find the full code in the attachment or on this GitHub link.