I begun work in a new project with lots of assemblies in a single solution. I am not familiar yet with the assembly dependencies and having a hard time figuring out which assembly depends on another.
Do you know any tools that are capable to show a dependency list or better a visual graph of it?
Any help appreciated !
Here is some quick code to show case the Cecil Library to do this:
public static void PoC(IEnumerable<AssemblyDefinition> assemblies, TextWriter writer)
{
Console.WriteLine("digraph Dependencies {");
var loaded = assemblies
.SelectMany(a => a.Modules.Cast<ModuleDefinition>())
.SelectMany(m => m.AssemblyReferences.Cast<AssemblyNameReference>().Select(a => a.Name + ".dll"))
.Distinct()
.Select(dllname => {
try { return AssemblyFactory.GetAssembly(dllname); }
catch { return null; } })
.Where(assembly => assembly != null)
.ToList();
loaded.ForEach(a => a.MainModule.FullLoad());
loaded.ForEach(a =>
{
foreach (var r in a.MainModule.AssemblyReferences.Cast<AssemblyNameReference>())
Console.WriteLine(@"""{0}"" -> ""{1}"";", r.Name, a.Name.Name);
} );
Console.WriteLine("}");
}
It generates a dot
graph file. Running this on a fairly simple project results in:
Running it on a slightly less simple project returned this:
It may be advisable to filter out certain assemblies (.StartsWith("System.")
?) and / or limit search depth etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With