Override Nuget packages dependency in order to use higher version of that dependency

1.3k Views Asked by At

Assuming we have .Net solution which contains multiple projects, one of these projects references a Nuget package A

(4.0.0 for example and this is the latest version of the package)

that references Newtonsoft.Json (9.0.1) for example, but doesn't figure as a dependency of the Nuget A.

I am not satisfied that project A is referencing that version (9.0.1) of Newtonsoft, and my question is there any solution to override the dependency of my Nuget A and force it to use Newtonsoft 13.0.1 for example?

I'm using packages.lock.json files and I reference my Nuget as PackageReference.

1

There are 1 best solutions below

0
Whaaa On

I may be reading the question wrong, but:

For override, you'd just want to add Newtonsoft.Json 13.0.1 to the top-level project and that would override the package version even if your referenced project has a lower-level package. Override would only happen of course when running your top-level project that has that higher-version reference.

An override that moves up that many versions would likely break, though.