Suppose I have a large .NET solution consisting of multiple projects. Each of these projects has some NuGet dependencies. These direct dependencies will also have some transitive dependencies but it's possible that the project in question doesn't actually need that transitive dependency.
Eg:
Package A:
public class A() {
}
public void DoSomething() {
Console.WriteLine();
}
public B CreateB() {
return new B();
}
Package B:
public B() {
;
}
If I have just 1 project in my solution that only uses A.DoSomething() and never calls A.CreateB() and also does not directly reference Package B, then even though B is a transitive dependency for my solution, it's not actually needed.
Is there some existing tool that helps me get a list of all packages that are actually needed by my solution?
I have a product which I ship through an installer. I often miss including transitive dependencies in the installer and as a result, the application fails at runtime.
This is interesting task and I think here is no simply answer (or maybe I don`t know it)
As for me solution will looks like external code analyze tool, previously i wrote something like this use Nuget package https://www.nuget.org/packages/Mono.Cecil/
This package it`s different reflection and you can use it for find information about every single line of code in your project.
So you need to:
after that you can match really used namespaces and nuget packages and which of them really used
Here is code example how you can do this:
This is just example you can upgrade it for your needs, but its works