Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet resolves the wrong version of package dependency

Tags:

.net

nuget

So I have a package, NServiceBus.Host that depends on NServiceBus >= 4.5.0.

On nuget there is a 4.5.1 version of NServiceBus. When I install-package NServiceBus.Host I get:

PM> install-package nservicebus.host
Attempting to resolve dependency 'NServiceBus (≥ 4.5.0)'.
Attempting to resolve dependency 'NServiceBus.Interfaces (≥ 4.5.0)'.
Installing 'NServiceBus.Interfaces 4.5.0'.
You are downloading NServiceBus.Interfaces from NServiceBus Ltd, the license agreement to which is available at http://particular.net/LicenseAgreement. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'NServiceBus.Interfaces 4.5.0'.
Installing 'NServiceBus 4.5.0'.

As you can see I get the 4.5.0 version of the dependency.

In the nuget doco it states:

If the dependency is not installed, NuGet goes through the following steps:

NuGet enumerates every version of Subkismet within the feed that’s within the version specification. NuGet then narrows that set to just the packages with the lowest Major/Minor version. Of the remaining packages, NuGet picks the one with the highest version number.

"NuGet picks the one with the highest version number." seems to be violated here since there is a never version.

Is this a bug in NuGet?

like image 257
Andreas Öhlund Avatar asked Apr 30 '14 09:04

Andreas Öhlund


People also ask

How do I change NuGet package version?

Right-click the Packages folder in the project, and select Update. This will update the NuGet package to the latest version. You can double-click the Add packages and choose the specific version.

How do I update NuGet dependencies?

By Command-line: You can download nuget.exe,and add the path where it exists to Path system environment variables. Then you could simply reference the nuget.exe directly. After that you can use command like nuget update YourSolution. sln in Package Manager Console to update the dependencies for solution.

Does NuGet automatically install dependencies?

Install NuGet packages without dependenciesBy default, when installing NuGet packages, corresponding package dependencies will also be installed in your project. To avoid the installation of dependent packages, choose the Ignore Dependencies option in the Dependency behavior drop-down in NuGet Package Manager.

Do NuGet packages include dependencies?

Any time a package is installed or reinstalled, which includes being installed as part of a restore process, NuGet also installs any additional packages on which that first package depends. Those immediate dependencies might then also have dependencies on their own, which can continue to an arbitrary depth.


2 Answers

The NuGet documentation on dependency resolution you refer to hasn't been updated since Dec 2010. The real NuGet docs are available here: https://docs.nuget.org

Also, NuGet will - by default - resolve the lowest major.minor version within the range allowed, as defined in the package dependencies. So 4.5.0 is a correct default dependency resolution.

New since NuGet v2.8.1: you can use an alternate dependency resolution algorithm using the NuGet Package Manager Console:

Install-Package NServiceBus.Host -DependencyVersion HighestPatch

There are more options, check the docs here: https://docs.nuget.org/docs/reference/package-manager-console-powershell-reference#Install-Package

like image 179
Xavier Decoster Avatar answered Oct 03 '22 13:10

Xavier Decoster


As Xavier mentioned this seems default behaviour. However, the documentation says you can change default behavior by editing nuget configuration:

Specifies the version of the dependency package to be selected from the list of valid dependency packages. The defult value is Lowest. You can override this default value by specifying a new default value in nuget.config file:

<configuration>
    <config>
        <add key="DependencyVersion" value="HighestPatch" />
    </config>
</configuration>

I edited my configuration file as described in the documentation:

%AppData%\Nuget\NuGet.Config

It then works in Powershell but NOT in a regular command prompt.

The docs also says:

What is strange is that the docs says that pre 2.7.2 the default was HighestPatch...

Note that for NuGet 2.7.2 or earlier, the default value is HighestPatch, and it cannot be changed.

The release notes of 2.8 mention the change in behavior and for the reason that install package now has a consistent dependency resolution result over time.

https://docs.nuget.org/docs/release-notes/nuget-2.8

like image 28
Ramon Smits Avatar answered Oct 03 '22 14:10

Ramon Smits