Home > Back-end >  How do I control the version of sub-dependencies in a C# project?
How do I control the version of sub-dependencies in a C# project?

Time:10-06

Our organization has an internal NuGet package with a dependency on Microsoft.Extensions.Logging.Abstractions, minimum version of 3.1.10.

One of our developers updated another NuGet dependency to a >5.0 version. This NuGet dependency also had a dependency on Microsoft.Extensions.Logging.Abstraction. This update caused all dependecies of Microsoft.Extensions.Logging.Abstraction to be moved up to >5.0.

The erroneously updated nuget dependency was reverted, although the sub-dependency for Microsoft.Extensions.Logging.Abstraction has not reverted to its 3.1.xx version, which is causing build failures because were running on .NET core 3.1, and not 5.xx

Is there a way to get the sub dependency Microsoft.Extensions.Logging.Abstraction down to v 3.1.10?

CodePudding user response:

Either something else has also changed or you're not running the restore from a clean state, as the version of Microsoft.Extensions.Logging.Abstractions would have gone back down again in the scenario you described.

There's a couple of ways to see where your problem is:

Longer more generally useful way

Delete your obj/ dir next to your project to make sure you're starting from a clean state, then run a dotnet restore.

Now open obj/project.assets.json. This lists all the packages in your dependency tree, together with the packages each one directly depends on.

Search for Microsoft.Extensions.Logging.Abstractions and check which version you've got. If it's still the higher version then you can see which package(s) are depending on it.

You can then trace the dependencies back until you end up at a package you reference directly, and you'll need to reference a lower version of that package.

Quick and easy way

Add a direct package reference to Microsoft.Extensions.Logging.Abstractions to your project at the version you want, then run dotnet restore. This will fail with package downgrade errors, and the error message will contain the dependency chain which is pulling in the higher version and causing the issue.

  • Related