简体   繁体   English

.NET Visual Studio 中的 6 个项目提供更新 NuGet 包到 7.0.0

[英].NET 6 project in Visual Studio offers update NuGet packages to 7.0.0

I have a .NET 6 ASP.NET Core project in VS 2022 and wonder if there is a way not to get .NET 7 packages in my NuGet update list?我在 VS 2022 中有一个 .NET 6 ASP.NET 核心项目,想知道是否有办法不在我的 NuGet 更新列表中获取 .NET 7 个包? Or am I supposed to update NutGet packages to 7.0.X?或者我应该将 NutGet 包更新到 7.0.X? What is the best practice?最佳做法是什么?

NuGet 包管理器

It's up to you to decide whether you want to upgrade or not.由您决定是否要升级。 These packages are just named V7.0.0, because they where released together with .NET 7.0.这些包只是命名为V7.0.0,因为它们与 .NET 7.0 一起发布。 For most (if not all) of these packages, there's no requirement that the runtime needs to be .NET 7.0.对于大多数(如果不是全部)这些包,没有要求运行时必须是 .NET 7.0。 Just read it as V7.0 of that package .只需将其作为package的 V7.0 阅读即可。 You can update (and even use new features) of these packages without updating the runtime of your application.您可以在不更新应用程序运行时的情况下更新(甚至使用新功能)这些包。

Check dependencies for the corresponding packages.检查相应包的依赖关系。 For example Microsoft.Extensions.DependencyInjection 7.0.0 specifies next supported frameworks and dependecies:例如Microsoft.Extensions.DependencyInjection 7.0.0指定下一个支持的框架和依赖项:

  • .NETFramework 4.6.2 .NETFramework 4.6.2
    • Microsoft.Bcl.AsyncInterfaces (>= 7.0.0) Microsoft.Bcl.AsyncInterfaces (>= 7.0.0)
    • Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0) Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
    • System.Threading.Tasks.Extensions (>= 4.5.4) System.Threading.Tasks.Extensions (>= 4.5.4)
  • .NETStandard 2.0 .NET 标准 2.0
    • Microsoft.Bcl.AsyncInterfaces (>= 7.0.0) Microsoft.Bcl.AsyncInterfaces (>= 7.0.0)
    • Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0) Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
    • System.Threading.Tasks.Extensions (>= 4.5.4) System.Threading.Tasks.Extensions (>= 4.5.4)
  • .NETStandard 2.1 .NET 标准 2.1
    • Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0) Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
  • net6.0 net6.0
    • Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0) Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
  • net7.0 net7.0
    • Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0) Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)

But for example Microsoft.AspNetCore.Authentication.JwtBearer 7.0.0 is only supported only for .NET 7 (my guess would be that either all or almost all ASP.NET Core packages would behave the same way):但是例如Microsoft.AspNetCore.Authentication.JwtBearer 7.0.0仅支持 .NET 7(我的猜测是所有或几乎所有 ASP.NET Core 包的行为方式相同):

  • net7.0 net7.0
    • Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 6.15.1) Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 6.15.1)

So while in theory you can upgrade some of dependencies but definitely not all without updating target framework version.因此,虽然理论上您可以升级一些依赖项,但绝对不能在不更新目标框架版本的情况下升级所有依赖项。 In general case I prefer to update either everything to the next major version or nothing (for packages supporting the "tied to runtime" versioning).在一般情况下,我更喜欢将所有内容更新到下一个主要版本或什么都不更新(对于支持“绑定到运行时”版本控制的包)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM