Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet ignoring newer version of dependency

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?

like image 561
Sam Bunting Avatar asked Mar 07 '23 22:03

Sam Bunting


1 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://learn.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

like image 84
Leo Liu-MSFT Avatar answered Mar 14 '23 19:03

Leo Liu-MSFT