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.
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.
- 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.
Now, restore the project by entering the following command: "dotnet restore".
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.
- public class Program {
- public static void Main(string[] args) {
- CreateWebHostBuilder(args).Build().Run();
- }
- public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args).UseStartup < Startup > ();
- }
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.