3

ASP.NET 6.0 Core 迁移 ASP.NET Core 7.0 - Eric zhou

 1 year ago
source link: https://www.cnblogs.com/tianqing/p/17054106.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

ASP.NET 6.0 Core 迁移 ASP.NET Core 7.0

2022年微软发布了.NET 7, 同时提供了详细的升级迁移方案。

Migrate from ASP.NET Core 6.0 to 7.0

今天给大家简单整理、分享一篇文章。

一、首先需要升级Visual Studio 2022或者VS Code

23525-20230115203819528-444564240.png

   VS Code升级最新版本,或者安装.NET 7 SDK.

   VS升级完成后,使用VS 2022打开已有的ASP.NET Core 6.0的代码工程。然后进行以下修改。

二、更新Global.JSON中.NET Core SDK

    如果依赖于global.json文件以特定的.NET Core SDK版本为目标,将版本属性更新为已安装的.NET 7.0 SDK版本。例如:

{
  "sdk": {
     "version": "7.0.100"
  }
}

 三、 修改项目工程的Target Framework

    修改各个项目工程的目标框架属性,改为net7.0

    Update the project file's Target Framework Moniker (TFM) to net7.0:

<PropertyGroup>
        <TargetFrameworks>net7.0</TargetFrameworks>
        <RootNamespace>Teld.Core.ServiceGateway.WebAPI</RootNamespace>
        <AssemblyName>TeldSG</AssemblyName>
        <UserSecretsId>0e9a6ca5-b196-48d0-a804-58e66bf93041</UserSecretsId>
    </PropertyGroup>

当然也可以使用  <TargetFrameworks>netstandard2.1;net451;net6.0;net7.0</TargetFrameworks>

四、升级Nuget包引用

  在项目文件中,将每个Microsoft.AspNetCore.*、Microsoft.EntityFrameworkCore.*,Microsoft.Extensions.*和System.Net.Http.Json包引用的Version属性更新为7.0.0或更高版本。

<ItemGroup>
 <PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="7.0.0" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
  <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0" />
  <PackageReference Include="System.Net.Http.Json" Version="7.0.0" />
</ItemGroup>

上述这一波操作后,ASP.NET Core 6.0的工程,就可以升级到ASP.NET Core 7.0.

2023/1/16


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK