我需要帮助来升级 ASP.NET Core 8 Web API 项目中已弃用的依赖项

问题描述 投票:0回答:1

我刚刚将 ASP.NET Core Web API 项目从 .NET 6 升级到 .NET 8。我想删除所有已弃用的依赖项,但遇到了一些问题。

例如,当将

Microsoft.Data.SqlClient
从3.1.0更新到5.2.0时,我收到以下错误

错误NU1605
警告错误:检测到包降级:System.Threading.Tasks 从 4.3.0 到 4.0.11。直接从项目中引用包来选择不同的版本。
BD.Shared.DWA -> Microsoft.AspNetCore.Mvc.Core 2.2.5 -> Microsoft.Extensions.DependencyModel 2.1.0 -> Microsoft.DotNet.PlatformAbstractions 2.1.0 -> System.IO.FileSystem 4.0.1 -> 运行时.win.System.IO.FileSystem 4.3.0 -> System.Threading.Tasks (>= 4.3.0)
BD.Shared.DWA -> Microsoft.AspNetCore.Mvc.Core 2.2.5 -> Microsoft.Extensions.DependencyModel 2.1.0 -> Microsoft.DotNet.PlatformAbstractions 2.1.0 -> System.IO.FileSystem 4.0.1 -> 系统.Threading.Tasks (>= 4.0.11) BD.Shared.DWA D:\GIT\DWA\MAIN\BD.Shared.DWA\BD.Shared.DWA.csproj 1

事实上,依赖项

Microsoft.AspNetCore.Mvc.Core
(也已弃用)包含对
System.Threading.Tasks
v4.0.11

的依赖项

这是项目文件

<PropertyGroup Label="Globals">
  <SccProjectName>SAK</SccProjectName>
  <SccProvider>SAK</SccProvider>
  <SccAuxPath>SAK</SccAuxPath>
  <SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>

<PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Platforms>AnyCPU;x64</Platforms>
    <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ProduceReferenceAssembly>False</ProduceReferenceAssembly>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="HtmlAgilityPack" Version="1.11.36" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
    <PackageReference Include="Microsoft.Data.SqlClient" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
    <PackageReference Include="MongoDB.Driver" Version="2.15.0" />
    <PackageReference Include="System.Diagnostics.PerformanceCounter" Version="7.0.0" />
    <PackageReference Include="System.Threading.Tasks" Version="4.0.11" />
</ItemGroup>

<ItemGroup>
  <Folder Include="Properties\PublishProfiles\" />
</ItemGroup>

<ItemGroup>
  <ProjectReference Include="..\DWA.Logging\DWA.Logging.csproj" />
  <ProjectReference Include="..\DWA.Product.Configuration\DWA.Product.Configuration.csproj" />
</ItemGroup>

<ItemGroup>
  <None Update="BD.Shared.DWA.nlog">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
  <None Update="Config\BD.Shared.DWA.Production.json">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
  <None Update="Config\BD.Shared.DWA.Staging.json">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
  <None Update="Config\BD.Shared.DWA.Development.json">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
  <None Update="Config\BD.Shared.DWA.Local.json">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
</ItemGroup>

有办法升级

Microsoft.Data.SqlClient
到5.0.2吗?

Microsoft.AspNetCore.Mvc.Core
已弃用,但不是新版本,我可以用什么替换它?

asp.net-core .net-core dependencies .net-6.0 .net-8.0
1个回答
0
投票

您已经明确安装了

System.Threading.Tasks
- 删除它。

还要删除所有

Microsoft.AspNetCore.*
包,这些包也已过时,应该在从 ASP.NET Core 2 升级时删除 - 请参阅从 ASP.NET Core 2.2 迁移到 3.0 指南:

大量 NuGet 包不是为 ASP.NET Core 3.0 生成的。应从您的项目文件中删除此类包引用。

因此,这些包不再分发,而是随框架/运行时本身一起提供。

© www.soinside.com 2019 - 2024. All rights reserved.