简体   繁体   中英

.NET — Managing NuGet packages’ common dependencies with different versions

I have two solutions: SolutionA and SolutionB (in separate repositories). Both solutions have dependencies on Package1, but projects under SolutionA leverage version 1.0.0 of this package, but projects under SolutionB leverages 2.0.0.

Now, a need arises to pack and publish a NuGet package of a library in SolutionB, which will be consumed in libraries in SolutionA.

As expected, I see a downgrade error when trying this. So, I decide to downgrade the version of Package1 in SolutionB to version 1.0.0. Code still compiles; there are no bad side-effects during run-time. Then, I pack and publish and try to reconsume in SolutionA edit: At this point, I have tried reinstalling the newest version of the SolutionB NuGet package by both uninstalling it completely then reinstalling and just downgrading it directly within NuGet Package Manager (w/e it's called..) within VS

At this point, I still see a downgrade error, citing that the SolutionB dependency is leveraging a higher version, but in reality, it isn't anymore. Why?

Halp!!

edit: adding the error for reference. I chose Newtonsoft.Json to demonstrate. This is easy to reproduce with, really, any NuGet package with multiple versions

Error NU1605 Detected package downgrade: Newtonsoft.Json from 11.0.2 to 9.0.1. Reference the package directly from the project to select a different version. TestProjectA -> TestProjectB 1.0.0 -> Newtonsoft.Json (>= 11.0.2) TestProjectA -> Newtonsoft.Json (>= 9.0.1)

TestProjectA's NuGet dependencies:

在此处输入图片说明

TestProjectB's NuGet dependencies:

在此处输入图片说明

确保在更改 TestProjectB 时,增加 NuGet 包版本或清除本地 NuGet 缓存( dotnet nuget locals all --clear )。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM