Tool to show assembly dependencies

安稳与你 提交于 2019-12-31 14:32:03

问题


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 !


回答1:


NDepend is the king when it comes to dependency graph analysis. The tool proposes:

  • a dependency graph
  • a dependency matrix,
  • and also some C# LINQ queries can be edited (or generated) to browse dependencies.

See all details in this Stackoverflow answer concerning a related question.




回答2:


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:

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.



来源:https://stackoverflow.com/questions/9262464/tool-to-show-assembly-dependencies

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!