3

I've a directory with a large number of dlls. I need to find all those that reference a specific dll.

I'm thinking about the following solution :

  1. Loop the assemblies and invoke each one with ildasm
  2. Dump the manifest into a text file
  3. Search the text files for the required assembly name.

Yet this solution feels immensely wrong to me. Is there a better way to achieve it?

4

4 回答 4

12

您可以为此编写一个小工具,使用反射来查找引用的程序集:

string[] fileNames = ...; // get all the filenames
foreach (string fileName in fileNames) {
    var assembly = System.Reflection.Assembly.ReflectionOnlyLoadFrom(fileName);
    var referencedAssemblies = assembly.GetReferencedAssemblies();

    foreach (var assemblyName in referencedAssemblies) {
        // do your comparison
    }
}
于 2013-12-25T10:27:10.417 回答
0

根据微软文档nn AppDomain.CurrentDomain.GetAssemblies() 获取已经加载到这个应用程序域的执行上下文中的程序集。关于 AppDomain.CurrentDomain.GetAssemblies()

看来您需要更改加载所需程序集的策略,从使用 appdomain 到在应用程序文件夹中查找 dll。

我在这里找到了关于类似问题的讨论

于 2013-12-25T10:48:01.127 回答
0

下载 AsmSpy.exe,它可以选择列出所有程序集和程序集中的所有引用。

https://github.com/mikehadlow/AsmSpy

于 2018-01-23T20:22:04.337 回答
0

下载 IlSpy.exe,然后打开您想查看其引用的程序集,它将列出所有引用的程序集。

https://github.com/icsharpcode/ILSpy/releases

于 2019-05-26T16:33:35.700 回答