3
votes

The library I am packaging as a NuGet package uses await/async, so I need to add a dependency to Microsoft.Bcl.Async. But Microsoft.Bcl.Async has dependencies on Microsoft.Bcl and Microsoft.Bcl.Build. What happens in a test project that I am getting different versions of these packages from NuGet.org depending on the order of installing them.

If I install Microsoft.Bcl.Async, then NuGet installs the following packages:

package id="Microsoft.Bcl.Build" version="1.0.4" 
package id="Microsoft.Bcl" version="1.0.19"  
package id="Microsoft.Bcl.Async" version="1.0.165" 

Then my test project doesn't compile.

If I first install Microsoft.Bcl, NuGet installs the following:

package id="Microsoft.Bcl.Build" version="1.0.10" 
package id="Microsoft.Bcl" version="1.1.6" 

Then I can install Microsoft.Bcl.Async:

package id="Microsoft.Bcl.Async" version="1.0.165" 

The test project doesn't compile.

But if I install all three BCL projects manually one by one, I am getting the following:

package id="Microsoft.Bcl.Build" version="1.0.13" 
package id="Microsoft.Bcl" version="1.1.6" 
package id="Microsoft.Bcl.Async" version="1.0.165" 

And only then my test project compiles successfully!

I must have misunderstood how NuGet version resolution works, but isn't NuGet supposed to resolve packages to the most recent version within the compatibility boundaries? The scenario above shows that NuGet fetches the dependent version with the minimum supported number: Microsoft.Bcl.Async 1.0.165 requires Microsoft.Bcl 1.0.19 or higher, and NuGet takes 1.0.19. Microsoft.Bcl 1.0.19 requires Microsoft.Bcl.Build 1.0.4 or higher, and NuGet takes 1.0.4. In the end it's a combination of oldest compatible packages (and apparently it doesn't properly work).

If this is a default behavior, then is this possible to override it?

1

1 Answers

4
votes

isn't NuGet supposed to resolve packages to the most recent version within the compatibility boundaries?

No. NuGet will actually choose the lowest major/minor version and the highest patch version. The rationale for this is because major versions can introduce breaking changes, minor versions can introduce new features (and therefore a higher likelihood of introducing bugs), but patch versions can only fix bugs.

If this is a default behavior, then is this possible to override it?

Since your library requires a specific version of those libraries, just add a version attribute to the appropriate dependency nodes in your nuspec.