How to specify specific dependency version in nuspec?

C#.NetNugetNuget Package

C# Problem Overview


I'm creating my first nuget package. I added a dependency with a version that is not the latest version. However, I don't want to update to the latest version of this dependency. Is it possible to instruct it to use the specific version?

<dependencies>
  <dependency id="NHibernate" version="3.2.0.3001" />
</dependencies>

When I install the package I see this:

Attempting to resolve dependency 'NHibernate (≥ 3.2.0.3001)'.

This creates the following when I install the package.

<packages>
  <package id="Iesi.Collections" version="3.2.0.4000" />
  <package id="NHibernate" version="3.2.0.4000" />
</packages>

I'd really like to see something like this: Attempting to resolve dependency 'NHibernate (3.2.0.3001)'.

C# Solutions


Solution 1 - C#

You should be able to force an exact version with brackets:

<dependency id="NHibernate" version="[3.2.0.3001]" />

Full info on the formats you can use are on the NuGet site, here:

http://docs.nuget.org/docs/reference/version-range-specification

Solution 2 - C#

From the NuGet docs site, the complete notations:

enter image description here

Solution 3 - C#

From the user side, you can also constrain the upgrade by specifying allowedVersions in the packages.config. http://docs.nuget.org/docs/reference/versioning#Constraining_Upgrades_To_Allowed_Versions

Solution 4 - C#

According to http://nuget.codeplex.com/wikipage?title=Dependency%20Resolution and other sources, simply specifying the lower bound as

<dependencies>
  <dependency id="NHibernate" version="3.2.0.3001" />
</dependencies>

will result in the highest revision/patch level of the lowest major/minor version matching that version.

Unless I completely misunderstand the documentation, this would match the highest 3.2.* version but not 3.3.* or greater versions unless no 3.2.* version could be found.

If there is some reason why 3.2.0.3001 is the only version against which you wish to depend, you may find that your package is not compatible with other packages which also depend on NHibernate for example because the other package depends on NHibernate [3.2.0.3002,3.3) which means at least 3.2.0.3002 but lower than 3.3.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondevlifeView Question on Stackoverflow
Solution 1 - C#Danny TuppenyView Answer on Stackoverflow
Solution 2 - C#Aviram FirebergerView Answer on Stackoverflow
Solution 3 - C#ferventcoderView Answer on Stackoverflow
Solution 4 - C#Chris LeeView Answer on Stackoverflow