Get DLL or EXE dependencies, using NDepend

I need to get the list of referenced assemblies used in EXE or DLL file. I was looking NDepend as an option to do it through its console so I can have a programatically solution for this.

As far as I know, NDepend reads dependencies from a Visual Studio project, but I don't know if it's possible to tell NDepend to analize a DLL and reads its referenced assemblies.

Anyone knows if it's possible to do it with NDepend? If not, there's another tool or mechanism that I can use to achieve this?

Thank you, Let me know if you need any extra detail.


  • Use Reflection to do it programmatically for managed references: http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getreferencedassemblies.aspx.
  • Or use a tool like JetBrain's dotPeek, also for managed references
  • Use Dependency Walker for other kinds of references: http://www.dependencywalker.com/faq.html

  • Whether you need a dependency graph, a dependency matrix or if you need these assemblies dependencies programatically NDepend can do that for you.

    so I can have a programatically solution for this.

    To get assemblies dependencies programatically you need to use NDepend.API. Here is the NDepend.API getting started documentation. Once you got a ICodeBase object in memory, here is how to get assemblies dependencies through a C# LINQ query for example:

    from a in codeBase.Application.Assemblies 
    where a.AssembliesUsed.Count() >= 0 
    orderby a.AssembliesUsed.Count() descending 
    select new { 
       a,
       a.AssembliesUsed,
       a.AssembliesUsingMe
    }
    

    Notice that a.AssembliesUsed is an IEnumerable<IAssembly> that contains application and third-party assemblies. To restraint a.AssembliesUsed to only application assemblies used you can rewrite it assembliesUsed = a.AssembliesUsed.Where(a1 => !a1.IsThirdParty) .

    Also, because NDepend API can be harnessed from C# LINQ query compiled and executed on-the-fly, you can run the previous C# LINQ query in the NDepend query editor in Visual Studio, and get the assemblies dependencies formatted in a convenient way:

    用NDepend汇编依赖关系

    链接地址: http://www.djcxy.com/p/37702.html

    上一篇: 得到过滤的程序集来分析

    下一篇: 使用NDepend获取DLL或EXE依赖关系