Get dependent assemblies?

后端 未结 4 1467
醉梦人生
醉梦人生 2021-02-01 06:48

Is there a way to get all assemblies that depend on a given assembly?

Pseudo:

Assembly a = GetAssembly();
var dependants = a.GetDependants();
         


        
4条回答
  •  萌比男神i
    2021-02-01 07:38

    Programatically, you can use Mono.Cecil to do this.

    Something like this (note this won't work if the debugger is attached - e.g. if you run it from inside VS itself):

    public static IEnumerable GetDependentAssembly(string assemblyFilePath)
    {
       //On my box, once I'd installed Mono, Mono.Cecil could be found at: 
       //C:\Program Files (x86)\Mono-2.10.8\lib\mono\gac\Mono.Cecil\0.9.4.0__0738eb9f132ed756\Mono.Cecil.dll
       var assembly = AssemblyDefinition.ReadAssembly(assemblyFilePath);
       return assembly.MainModule.AssemblyReferences.Select(reference => reference.FullName);
    }
    

    If you don't need to do this programatically, then NDepend or Reflector can give you this information.

提交回复
热议问题