Locking NuGet updates to major .NET version

Hi there,

Is there a way to lock NuGet package updates to a particular major version of .NET? Where I work we can only update our .NET version to LTS, so every other year we have to be very careful about not using “Upgrade Packages in Solution”

This occured for .NET 7 and now again for .NET 9

0
5 comments

Hello Lumai,

Thank you for contacting Rider support.

If I properly understand the problem and what you need, you might want to consider using the Central Package Management.

Using per-directory/per-solution/per-project .props files allows specifying exact versions of packages to be used.

If that doesn't help or you have any other questions or difficulties, please let me know.

Have a nice day!

0

Hi Dmitry,

Thanks for the reply! Central package management is great, but it unfortunately  doesn’t solve the issue I’m having. It’s more around ensuring versions of nuget packages don’t appear as an option to upgrade when they rely on other packages that would unintentionally raise the .NET version of packages. 

0

Hello Lumai,

To be on the same page, would you mind elaborating on the problem?

  • How exactly the issue occurs. Share a sample scenario;
  • Why doesn't CPM help in this scenario? It allows specifying NuGet packages versions to be used across Solution/Project/Directory.
  • Is the problem by chance in the fact that Rider allows pressing the "Upgrade" button?

  • Would this help by chance? RIDER-114107 NuGet Package Upgrade in Rider Doesn't Respect Version Ranges

Did you consider using a custom NuGet feed? A responsible person might upload proven-to-work nuget packages there, so that developers might use this NuGet feed instead of NuGet.org.

Have a nice day!

0

Hi, I had the same issue like Lumai,

You can add a version range to your `PackageReference` entry in your cspoj-file.

See Microsoft Learn: https://learn.microsoft.com/en-us/nuget/concepts/package-versioning?tabs=semver20sort#Constraining_Upgrades_To_Allowed_Versions

I was not able to edit the range via UI of Visual Studio, but easily inside the csproj-file.

Snippet of a csproj-file. The nuget package Microsoft.Extensions.Logging.Abstractions is limited to version at least 8.0.2, but no version from version 9 and above. Useful when you want to use only LTS versions of dotnet

```xml

<ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="[8.0.2,9.0)" />
</ItemGroup>

```

With these changes in the csproj files, Visual Studio will ignore v9 files in the nuget update window.

There is also my “answer” to a similar need on Stackoverflow https://stackoverflow.com/a/79468751/10655742

0

Hi Nk, thanks for the reply, I ended up seeing [) around but the version ranges table from https://learn.microsoft.com/en-us/nuget/concepts/package-versioning?tabs=semver20sort#Constraining_Upgrades_To_Allowed_Versions is very useful!

Unfortunately it seems that they are not all fully supported.

Thanks for sharing!

0

Please sign in to leave a comment.