How to detect transitive dependency versions to avoid issues. #12448
Replies: 1 comment 2 replies
-
A while back I had to do an analysis across a bunch of separate solutions that reference each other and used a combination of the I don't have quite enough time to extract the logic out, but here are some snippets that might help point you to the pieces of data I found helpful: // this was used to load the project.assets.json file
LockFile = LockFileUtilities.GetLockFile(Path.Combine(Path.GetDirectoryName(FullPath), @"obj\project.assets.json"), NuGet.Common.NullLogger.Instance)
// this is essentially the "minimum request version" of transitive dependencies
LockFile.Targets[...].Libraries[...].Dependencies[...].VersionRange.MinVersion
// this is the version that was restored by the project
LockFile.Libraries[...].Version I will say there is a new feature that looks like it would help with this (CentralPackageTransitivePinningEnabled, as part of Central Package Management). That feature still requires defining an explicit version for packages that need to be transitively overridden so hopefully this logic will still help. |
Beta Was this translation helpful? Give feedback.
-
Hi,
This is an issue discussed on here quite a bit, but my question isn't the standard 'what to do', but more 'how do I detect this is happening'.
Our codebase is about 500 project spread across 8ish solutions. We are having the following setup
WindowA depends on CSVHelper, JsonSerializer, OPCFoundation, etc.
WindowB depends on Entities, System.Collections, etc.
These nuget packages have transitive dependencies on several dlls, but in my case, it's System.Buffers. The issue we had was that whatever the last project compiles, is what dumped the version of System.Buffers it needed.
The correct solution, I believe, is to use
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
with CVPM, and specify<PackageVersion Include="System.Buffers" Version="4.5.1" Pin="true"/>
in the Directory.Packages.Config . This works!So, a few questions:
Thanks for any feedback others have :)
Beta Was this translation helpful? Give feedback.
All reactions