将 ASP.NET Core 2.0 项目升级至 ASP.NET Core 2.1

主要升级步骤如下:

将 .csproj 项目文件中的 target framework 改为 netcoreapp2.1

<TargetFramework>netcoreapp2.1</TargetFramework>

将 Microsoft 开头的 nuget 包升级为 2.1.0-rc1-final  (正式版改为 2.1.0 ),System 开头的 nuget 包升级为 4.5.0-rc1(正式版改为 4.5.0)(这个我没用)

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0-rc1-final" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.0-rc1" />

将 Microsoft.AspNetCore.All 更改为 Microsoft.AspNetCore.App

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

在 Program 中将 IWebHost 改为 IWebHostBuilder 

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
}

在 Startup 中添加 SetCompatibilityVersion

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
摘自:https://www.cnblogs.com/dudu/p/9009295.html
原文地址:https://www.cnblogs.com/djd66/p/9406149.html