dave clements
dave clements

Reputation: 1505

Set exact version for Nuget package dependency when using IncludeReferencedProjects

I have a solution with several projects in it. Each project has it's own nuspec file and some of the projects reference each other

When I create a new package by calling

nuget pack MyLibrary.csproj -IncludeReferencedProject

nuget is clever enough to add any referenced projects as dependencies, rather than bringing in the generated binaries, but it always sets the dependency version to

version="1.2.3.4"

which is interpreted as 1.2.3.4 or higher

I want to be able to tell nuget to set the version to

version="[1.2.3.4]"

so that dependencies are always exact

Is there any way I can do this without having to manually update and maintain the dependencies in the nuspec file for every project?

Upvotes: 5

Views: 2391

Answers (3)

Alex P.
Alex P.

Reputation: 3787

Use -Properties as described here https://nuget.codeplex.com/discussions/336207 or just $version$ if you use -Version to specify the package version and it is the same as the dependency version.

Upvotes: 0

s_hewitt
s_hewitt

Reputation: 4302

In the packages.config file for your project, specify the version like this:

<packages>
  <package id="example.dll" version="1.3" targetFramework="net451" allowedVersions="[1.3]" />
</packages>

Upvotes: 1

Fei Ling
Fei Ling

Reputation: 592

What you need to do is to write a tool that opens the generated package, changes the dependency restraints, and the saves the package. Note that you shouldn't set upper bound unless you have a really good reason to do so. See http://blog.davidebbo.com/2011/01/nuget-versioning-part-2-core-algorithm.html

Upvotes: 0

Related Questions