Consider a .NET Core application (A
), which references a third-party nuget package (B
) using the PackageReference
model. Package B
has it's own dependency on another package (C
):
A -> B -> C
Package B
declares a dependency on C
with a version constraint of >= 1.0.0
. A
has no compile-time usages of C
and does not reference it directly - C
is a transitive run-time dependency.
However, version 1.0.0 of package C
(which is picked up by the build) has a bug in it. The bug has been fixed in a more recent version, released to nuget with an incremented minor-version (e.g. v1.1.0).
By default, my build doesn't pick up this latest version. I believe this is due to the 'Lowest applicable version' rule, described here: https://learn.microsoft.com/en-us/nuget/concepts/dependency-resolution#dependency-resolution-rules
What is the recommended approach for forcing the build to pick up the bug-fix 1.1.0 version of package C
?
One solution is to explicitly reference the 1.1.0 version of package C
from A
. However, this feels like I'm breaking encapsulation, as A
shouldn't need to know anything about C
.
Ideally, the author of package B
would update their dependency on C
to use the newer version, but I don't have any control over this package.
I also tried using a Directory.Build.props
file at the root of the solution, to try and force the version to be updated across the whole solution:
<ItemGroup>
<PackageReference Update="SomePackage.C" Version="1.1.0" />
</ItemGroup>
...but this doesn't work (I assume the 'lowest applicable version' rule still applies). It does work if you use Include
instead of Update
, but that simply installs the package into all the projects in the solution.
I'd like to be able to supply some 'policy' to the build process, to force the updated version to be picked up, but I've not found a way to do this.
Note: my actual example is more complex than the one outlined here. Both B
and C
are widely-used Microsoft ASP.NET packages, and C
appears in dozens of places in the dependency graph (my own application never references that code directly).