Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool to show assembly dependencies

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 !

like image 1000
SvenG Avatar asked Feb 13 '12 14:02

SvenG


1 Answers

Here is some quick code to show case the Cecil Library to do this:

  • http://www.mono-project.com/Cecil

 

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:

enter image description here

Running it on a slightly less simple project returned this:

enter image description here

It may be advisable to filter out certain assemblies (.StartsWith("System.")?) and / or limit search depth etc.

like image 121
sehe Avatar answered Oct 21 '22 21:10

sehe