c# - 如何找到引用特定 dll 的所有程序集?

标签 c# dependencies assemblies ildasm

我有一个包含大量 dll 的目录。我需要找到所有引用特定 dll 的文件。

我正在考虑以下解决方案:

  1. 循环程序集并使用 ildasm 调用每个程序集
  2. list 转储到文本文件中
  3. 在文本文件中搜索所需的程序集名称。

但我觉得这个解决方案非常错误。有没有更好的方法来实现它?

最佳答案

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

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
    }
}

关于c# - 如何找到引用特定 dll 的所有程序集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20771512/

相关文章:

c# - 区分 Microsoft Excel 中的保存和自动保存事件

Linux 路径/依赖关系处理

.net - 装配体创建指南

plugins - Maven 读取程序集时出错 : No assembly descriptors found

.net - 主互操作程序集 (PIA)

c# - 在 Microsoft Azure 中对用户进行身份验证并管理其资源

c# - 如何在 C# 中检索 azure 安全组

c# - 为什么不能将可空值声明为 const?

node.js - 将 git 依赖项添加到 Nodejs 应用程序

c++ - 如何选择应用程序应链接到的 VC 2008 DLL 的版本?