I have a C# .NET 6 project where I need to find all NuGet packages that are referenced by the C# source but are not directly referenced in the project file. This can happen when the package is a transitive reference.
For example:
- My project contains a reference to package A
- Package A references package B
- My source code references types in package B
- But my project does not contain a reference to package B.
Project:
<PackageReference Include="A" Version="1.0.0"><!-- Note, no direct reference to B -->
C# Source:
using B;// ... class that references types from package B
This compiles and runs fine due to the transitive reference from A to B.
I have tried using dotnet list package
. That only includes direct references.
I have also tried using dotnet list package --include-transitive
. That includes all transitive references, including packages not references by my code.
Internet searches so far are not turning up any third-party utilities that appear to do what I need.
Is there any tool or technique to find the transitive packages referenced by my C# code?