Hurry Up! Upgrade Your .NET Core to Latest ASP.NET Core 3! – Windows ASP.NET Core Hosting 2019 | Review and Comparison

This article will shows how to upgrade your previous .NET Core to latest ASP.NET Core 3.0.

I used a new ASP.NET Core 3.0 Web Application (Razor Pages) project with Identity and the documentation to migrate the ASP.NET Core 2.2 – Bootstrap Native Project to .NET Core 3.0. When I tried to upgrade my aplication to .NET Core 3.0 I found a couple of issues. You should migrate a copy of your project to analyze and mitigate any issues.

Let’s start by editing the project file. Right click on the project then click Edit Project File.

Edit PROJECTNAME.csproj:
Update the Target Framework:
Optionally remove the AspNetCoreHostingModel property if its value is InProcess:
If TypeScriptToolsVersion, update version to Latest:
Remove obsolete package references:
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />

Now use the Nuget Manager to install new packages. Right click on the project then click Manage NuGet Packages. The Microsoft.AspNetCore.Mvc.NewtonsoftJson package is required for proper Admin > Users > Details serialization. 

On the Browse tab, search and install the following packages:
  • Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore
  • Microsoft.AspNetCore.Mvc.NewtonsoftJson
  • Microsoft.EntityFrameworkCore.SqlServer
  • Microsoft.EntityFrameworkCore.Tools
On the Installed tab, update:
  • Microsoft.VisualStudio.Web.CodeGeneration.Design

Update the Program class to use IHostBuilder.

Edit Program.cs, implement IHostBuilder:
public static void Main(string[] args)

public static IHostBuilder CreateHostBuilder(string[] args) => Host
    .ConfigureWebHostDefaults(webBuilder =>
        .ConfigureKestrel(serverOptions =>
            // Set properties and call methods on options

Update the namespaces with using Microsoft.Extensions.Hosting;.

Use Find and Replace > Current Project to replace IHostingEnvironment with IWebHostEnvironment then update the namespaces with using Microsoft.Extensions.Hosting;.

Edit IdentityHostingStartup.cs in the Areas > Identity > Pages folder, use Remove and Sort Usings to remove the namespace using Microsoft.AspNetCore.Identity.UI;.

Update the configuration in the Startup class.

Edit Startup.cs > ConfigureServices:
    .AddRazorPagesOptions(options =>
        options.AllowAreas = true;
        options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage");
        options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");
        options.Conventions.AuthorizeAreaPage("Admin", "/Index");
        options.Conventions.AuthorizeAreaFolder("Admin", "/Users");
services.AddRazorPages(options =>
        options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage");
        options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");
        options.Conventions.AuthorizeAreaPage("Admin", "/Index");
        options.Conventions.AuthorizeAreaFolder("Admin", "/Users");
Edit Startup.cs > Configure:
Add above app.UseAuthentication:
Add below app.UseAuthentication:
app.UseEndpoints(endpoints =>

Build, run and test.