AspNetCore.Docs/aspnetcore/migration/21-to-22.md

4.6 KiB

title author description ms.author ms.custom ms.date uid
Migrate from ASP.NET Core 2.1 to 2.2 scottaddie This article outlines the prerequisites and most common steps for migrating an ASP.NET Core 2.1 project to ASP.NET Core 2.2. scaddie mvc 12/08/2018 migration/21-to-22

Migrate from ASP.NET Core 2.1 to 2.2

By Scott Addie

This article explains how to update an existing ASP.NET Core 2.1 project to ASP.NET Core 2.2.

[!INCLUDE]

Update Target Framework Moniker (TFM)

Projects targeting .NET Core should use the TFM of a version greater than or equal to .NET Core 2.2. Update the <TargetFramework> node's inner text with netcoreapp2.2:

<TargetFramework>netcoreapp2.2</TargetFramework>

Projects targeting .NET Framework may continue to use the TFM of a version greater than or equal to .NET Framework 4.6.1:

<TargetFramework>net461</TargetFramework>

Adopt the IIS in-process hosting model

To adopt the in-process hosting model for IIS, add the <AspNetCoreHostingModel> property with a value of InProcess to a <PropertyGroup> in the project file:

<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

For more information, see xref:host-and-deploy/aspnet-core-module#hosting-model.

Update package references

If targeting .NET Core, remove the Version attribute for the metapackage reference. Inclusion of a Version attribute results in the following warning:

A PackageReference to 'Microsoft.AspNetCore.App' specified a Version of `2.2.0`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs

The metapackage reference should resemble the following <PackageReference /> node:

<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

If targeting .NET Framework, update each package reference's Version attribute to 2.2.0 or later. Here are the package references in a typical ASP.NET Core 2.2 project targeting .NET Framework:

<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
  <PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.2.0" />
  <PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" />
  <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
  <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
</ItemGroup>

Update .NET Core SDK version in global.json

If your solution relies upon a global.json file to target a specific .NET Core SDK version, update its version property to the 2.2 version installed on your machine:

{
  "sdk": {
    "version": "2.2.100"
  }
}

Call ConfigureKestrel instead of UseKestrel

If the app calls xref:Microsoft.AspNetCore.Hosting.WebHostBuilderKestrelExtensions.UseKestrel* in the CreateWebHostBuilder method of the Program class, call ConfigureKestrel instead to avoid conflicts with the IIS in-process hosting model:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .ConfigureKestrel((context, options) =>
        {
            // Set properties and call methods on options
        });

For more information, see xref:fundamentals/servers/kestrel#how-to-use-kestrel-in-aspnet-core-apps.

Update compatibility version

Update the compatibility version in Startup.ConfigureServices to Version_2_2:

services.AddMvc()
        .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

Update Docker images

The following table shows the Docker image tag changes:

2.1 2.2
microsoft/dotnet:2.1-aspnetcore-runtime microsoft/dotnet:2.2-aspnetcore-runtime
microsoft/dotnet:2.1-sdk microsoft/dotnet:2.2-sdk

Change the FROM lines in your Dockerfile to use the new image tags in the preceding table's 2.2 column.

Additional resources