NuGet ignoring newer version of dependency

Viewed 4079

I have two NuGet Packages. Package One, and package Two. Package Two needs to have an dependency as Package One version 1.0 or higher.

I have made a small change to Package One and re-built the NuGet Package to the version of 1.0.1. I have not made any changes to the Package Two NuGet package. I have also updated Package One in the solution I am working in.

The issue I am having is that Package Two is still trying to look for the .dll of Package One of version 1.0, an old version. Yet there is the newer version already installed and available to use, it is like it is ignoring it.

Package Two has the dependency of version 1.0 or higher of Package One in the package.nuspec file.

Is there any way to resolve this?

2 Answers

Is there any way to resolve this?

Just as Matt answered "This is the default behaviour of NuGet":

With NuGet 2.5 and later, if a dependency version is already satisfied, the dependency isn't updated during other package installations.

So 1.0 is a correct default dependency resolution.

Since NuGet v2.8, we could use other dependency resolution algorithms:

Though NuGet 2.8 changes the default behavior for resolving dependencies, it also adds more precise control over dependency resolution process via the -DependencyVersion switch in the package manager console. The switch enables resolving dependencies to the lowest possible version (default behavior), the highest possible version, or the highest minor or patch version.

The detail information about the those dependency resolution algorithms, please check below document:

https://docs.microsoft.com/en-us/nuget/tools/ps-ref-install-package

enter image description here

To resolve this issue, you can use below command in the Package Manager Console:

Install-Package PackageTwo -DependencyVersion Highest

Or chose it from Manage NuGet package UI by expending Options:

enter image description here

This is the default behaviour of NuGet where it will install the lowest patch version of a dependency.

https://docs.microsoft.com/en-us/nuget/consume-packages/dependency-resolution

You can override this globally in NuGet.Config, for example:

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

Or you can specify this when installing the NuGet package in Visual Studio.

Otherwise you are left with modifying Package Two to depend on 1.0.1 of PackageOne which is probably not what you want to do since Package Two will still work with the older version of Package One.

Related