My Experience Updating a Web App from ASP.NET Core 1.1 to ASP.NET Core 2.0

With the release of ASP.NET Core 2.0 earlier today, I decided to update the web app I am developing from ASP.NET Core 1.1 to ASP.NET Core 2.0 to take advantage of the benefits of the updated frameworks.

To update the project to ASP.NET Core 2.0, I performed the following steps:

  1. Installed Visual Studio 2017 Version 15.3
  2. Installed the Microsoft .NET Core 2.0 SDK
  3. Updated the csproj file.
  4. Closed Visual Studio and deleted the bin, node_modules, and obj folders from the project folder.
  5. Fixed compiler errors and tested.

The updated csproj file:

I did however run into a few issues requiring me to update the code in order for the project to compile correctly using ASP.NET Core 2.0.

Some classes have been moved to different namespaces.

IAuthorizationService.AuthorizeAsync(…) no longer returns a Task<bool>. Instead it returns a Task<AuthorizationResult> which has a Succeeded property that can be used to replicate how the old method worked.

IdentityUser uses a string with a guid value as its primary key. Originally, I was using IdentityUser<Guid> but switched to just IdentityUser.

In the Startup class, services.AddDbContext<T>(…) can be replaced with services.AddDbContextPool<T>(…) for added performance by re-using instances of the DbContext but there are a few caveats as explained in the documentation.

The Program class has been simplified, so unless you are using a heavily modified version, it is probably best to replace it with the new version.

If you are implementing classes using IAuthorizationHandler that use the DbContext, you should register them using services.AddScoped<IAuthorizationHandler, T>() instead of services.AddSingleton<IAuthorizationHandler, T>().

Overall, the upgrade took me a couple of hours (including the testing) and the end result is having the added functionality and performance as well as the ability to hopefully upgrade to future ASP.NET Core 2.x and Entity Framework Core 2.x releases with ease.

The project that was upgraded to ASP.NET Core 2.0 can be found at: https://github.com/jonathanpotts/TripShare