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
Please sign in to leave a comment.
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!
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.
Hello Lumai,
To be on the same page, would you mind elaborating on the problem?
Is the problem by chance in the fact that Rider allows pressing the "Upgrade" button?
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!
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.Abstractionsis 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
```
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
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!