Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict nuget package updates to current versions for some packages

Is there a way to disable updates of specific nuget packages installed in a project?

I have made some local modifications to a couple of javascript library packages and do not want to run the risk of someone updating over the top of my changes in the future.

I've never created my own nuget package, I'm guessing one option might be to fork the existing packages?

like image 923
Marc Avatar asked Mar 21 '14 15:03

Marc


People also ask

How do I change NuGet package version?

Right-click the Packages folder in the project, and select Update. This will update the NuGet package to the latest version. You can double-click the Add packages and choose the specific version.

How do I allow NuGet to download missing packages?

To do that, go to Tools, NuGet Packaged Manager, then go to Package Manager Settings. Go to the General section, and then make sure you have a checkmark for Allow NuGet to download missing packages and also to automatically check for missing packages during the build in Visual Studio. So click on OK.


2 Answers

You could try constraining the package so it your project will only allow a particular version to be used. Then all updates to any newer version will be prevented.

You can do this by editing your project's package.config file. For example, the line below should only allow version 2.1.0 to be used.

<package id="SomePackage" version="2.1.0" allowedVersions="[2.1.0]" />
like image 179
Matt Ward Avatar answered Sep 18 '22 09:09

Matt Ward


I don't have a package.config. (VS 2019, .NET Core 3.1) What I did instead was changing the .csproj of the project which had the package which I needed to stop showing up for updates.

In my case it was EPPlus, and I wrapped the version number within square brackets.

<ItemGroup>
    <PackageReference Include="EPPlus" Version="[4.5.3.3]" />
</ItemGroup>

After that, it stopped showing up on the Updates tab in Nuget Package Manager.

And it doesn't give any option to update from anywhere else too. (Installed tab, Nuget for the solution, etc)

You'll need to restart VS to get rid of the yellow triangles next to the packages.

like image 31
Ε Г И І И О Avatar answered Sep 19 '22 09:09

Ε Г И І И О