Serj Sagan
Serj Sagan

Reputation: 30208

How to Lock a Package Version from Nuget Updates

I am using Aspose to do some doc management and our license only gives us a year of updates, which now has expired. So when, in typical fashion, we update our packages and get the latest version of Aspose it breaks our app. Is there a way to lock down those packages from showing up in the Nuget Package Updates list, or at least to prevent changes to the versions via the the Nuget Update process? I looked at various Nuget and Microsoft references and didn't see anything, but am hoping someone here knows some secret sauce?

Nuget Package Manager

Upvotes: 13

Views: 6001

Answers (4)

Alex from Jitbit
Alex from Jitbit

Reputation: 60616

With the latest PackageReference format simply add square brackets around the version number in .csproj file:

<PackageReference Include="MYPACKAGE" Version="[2.6.0]" />

This will freeze the dependency version and it won't show up in updates.

Docs: https://learn.microsoft.com/en-us/nuget/concepts/package-versioning?tabs=semver20sort#version-ranges

P.S. This is an old question but it still shows up as the #1 Google result for me, so I added another answer.

Upvotes: 19

Pelle
Pelle

Reputation: 63

I know this question is old but there is an attribute you can add in the packages.config file that locks the version as Matt Ward answered here:

Restrict nuget package updates to current versions for some packages

For us it was the UmbracoCms package that had breaking changes in the next version.

<package id="UmbracoCms" version="7.15.5" allowedVersions="[7.15.5]" targetFramework="net472" />

You can find more information about version restrictions here

Upvotes: 4

Gabriel Luci
Gabriel Luci

Reputation: 40918

One way is to just stop using NuGet for it and reference the DLLs manually.

  1. Look in the bin folder (where your compiled project is) and copy any Aspose.* files to a new folder in your project directory.
  2. Uninstall the Aspose NuGet packages.
  3. In Visual Studio Solution Explorer, right-click 'References' -> 'Add Reference' -> 'Browse' -> 'Browse' and pick the DLLs from the folder you created in step 1.

Upvotes: 1

erendrake
erendrake

Reputation: 31

The two ways I can think to do this:

  • Create a new Nuget package that you dont rev that contains the references you want to lock. that way they would just never show up in the update list.
  • Create a test like @mason suggested. I would start with code that finds the assembly with the name you want to lock then you can check its version. you can either write it as an exact match (easist) or not to exceed a specific version (more work but you could use an earlier version)

Upvotes: 2

Related Questions