Install the exact version for the Nuget package dependency when using IncludeReferencedProjects

I have a solution with several projects. Each project has its own nuspec file, and some projects link to each other.

When I create a new package, calling

nuget pack MyLibrary.csproj -IncludeReferencedProject 

nuget is smart enough to add any related projects as dependencies, rather than result in generated binaries, but it always installs the dependency version

 version="1.2.3.4" 

which is interpreted as 1.2.3.4 or higher

I want to say nuget to install the version

 version="[1.2.3.4]" 

so the dependencies are always accurate

Can I do this without having to manually update and maintain the dependencies in the nuspec file for each project?

+4
source share
4 answers

What you need to do is write a tool that opens the generated package, changes the dependency restrictions and saves the package. Please note that you should not set an upper bound unless you have a really good reason for this. See http://blog.davidebbo.com/2011/01/nuget-versioning-part-2-core-algorithm.html

0
source

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

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

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

0
source

Nugget says we should use this syntax [version] to set the exact version. Example:

 <package id="Newtonsoft.Json" version="[9.0.1]" targetFramework="net45" /> 

A full description can be found here: https://docs.nuget.org/ndocs/create-packages/dependency-versions

Update: I tested it, but I get an error:

An error occurred while reading the file 'C: \ Repo \ MyProject \ MyProj.V1 \ MyProj.V1.Loads \ packages.config': invalid package version for package identifier 'Newtonsoft.Json': '[9.0.1]

0
source

Source: https://habr.com/ru/post/1486861/


All Articles