On December 4th .NET Core 2.2 including ASP.NET Core 2.2 and Entity Framework 2.2. In this post, I will be taking one of the projects used in the ASP.NET Basics series and converting it from ASP.NET 2.1.x to the new 2.2 version of ASP.NET Core. This will all be based on the official 2.2 migration guide.
The code before any changes can be found here. In the sample solution, this guide will be working with the Contacts project only.
Installation
Head over to the .NET download page and download the new version of the .NET Core SDK for version 2.2 which is available for Window, Linux and Mac.
After installation is done run the following command if you want to verify the SDK is installed.
dotnet --list-sdks
You should see 2.2.100 listed. If you are like me you might also see a few preview versions that would be good to uninstall.
If you are using Visual Studio make sure you are on at least version 15.9. If not updates can be downloaded from here.
Project File Changes
Right-click on the project and select Edit projectName.csproj.
Change the TargetFramework to netcoreapp2.2.
Before: <TargetFramework>netcoreapp2.1</TargetFramework> After: <TargetFramework>netcoreapp2.2</TargetFramework>
Update any Microsoft packages with a version to 2.2.x the following is an example.
Before: <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" PrivateAssets="All" /> After: <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" PrivateAssets="All" />
If you want to use the new IIS in-process hosting model you also need to add the following line to a property group.
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
The following is my full csproj for reference.
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.2</TargetFramework> <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> <UserSecretsId>aspnet-Contacts-cd2c7b27-e79c-43c7-b3ef-1ecb04374b70</UserSecretsId> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" PrivateAssets="All" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" /> </ItemGroup> </Project>
Startup Changes
In Startup.cs update the compatibility version to enable the new 2.2 features.
Before: services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); After: services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
Wrapping Up
As with the migration to 2.1 the move to 2.2 is really easy to do. Make sure you check out the official migration guide for more details that may have not been covered by this project.
The code in its final state can be found here.
Also published on Medium.
Thanks, this really helped!
Glad to hear it, Chris!