Home > Enterprise >  .NET 6 project in Visual Studio offers update NuGet packages to 7.0.0
.NET 6 project in Visual Studio offers update NuGet packages to 7.0.0

Time:12-13

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? Or am I supposed to update NutGet packages to 7.0.X? What is the best practice?

NuGet package manager

CodePudding user response:

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. For most (if not all) of these packages, there's no requirement that the runtime needs to be .NET 7.0. Just read it as V7.0 of that package. You can update (and even use new features) of these packages without updating the runtime of your application.

CodePudding user response:

Check dependencies for the corresponding packages. For example Microsoft.Extensions.DependencyInjection 7.0.0 specifies next supported frameworks and dependecies:

  • .NETFramework 4.6.2
    • Microsoft.Bcl.AsyncInterfaces (>= 7.0.0)
    • Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
    • System.Threading.Tasks.Extensions (>= 4.5.4)
  • .NETStandard 2.0
    • Microsoft.Bcl.AsyncInterfaces (>= 7.0.0)
    • Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
    • System.Threading.Tasks.Extensions (>= 4.5.4)
  • .NETStandard 2.1
    • Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
  • net6.0
    • Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
  • net7.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):

  • net7.0
    • 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).

  • Related