.NET DLL 引用/依赖性检查实用程序

发布于 2024-12-25 06:48:36 字数 310 浏览 1 评论 0原文

使用 Visual Studio,我可以看到 dll 引用,如附图所示。 有了这些参考信息,我可以打开(来自示例)Composition 项目来查找所有其他参考,从而获取所有参考文件名。

有没有任何实用程序可以自动完成这项工作? 我的意思是,给定一个 .NET 程序集,它会递归地检查所有引用/依赖项以给出 DLL 的名称。

我检查了cygwin的ldd和Depends.exe,但它们似乎没有显示其他项目的dll,而只显示系统dll。

在此处输入图像描述

With Visual Studio, I can see the dll references as the attached picture as an example.
With this reference information, I can open the (from the example) Composition project to find all the other references on and on to get all the reference file names.

Is there any utility that does this job automatically?
I mean, given an .NET assembly, it checks all the references/dependencies recursively to give the names of DLLs.

I checked cygwin's ldd and Depends.exe, but they don't seem to show the dlls from other projects, but only system dlls.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

蓝礼 2025-01-01 06:48:36

是:ildasm.exe。它与 SDK 一起安装。

应位于以下路径:C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin

Yes: ildasm.exe. It is installed with the SDK.

Should be in a path like: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin

沫尐诺 2025-01-01 06:48:36

我喜欢使用 AsmSpy 进行此类检查。有一个可执行文件可供下载,然后我将其放入我的工具文件夹中以便于访问。
https://github.com/mikehadlow/AsmSpy

I like to use AsmSpy for this type of check. There is a single exe to download and then I put it into my tools folder for easy access.
https://github.com/mikehadlow/AsmSpy

定格我的天空 2025-01-01 06:48:36

您可以使用提供的 ildasm.exe,或者如果您想要更强大的东西,您可以尝试:

Reflector

更好的是,尝试免费

dotPeek

You can use the provided ildasm.exe, or if you want something a little bit more powerfull, you can try:

Reflector

Even better, try the free:

dotPeek

简美 2025-01-01 06:48:36

我不知道有什么工具可以自动为您执行此操作,但我可以概述任何工具(或您)必须遵循的步骤。

每个程序集都包含一个清单。该清单列出了当前程序集所依赖的所有其他程序集的名称和版本。最简单的情况是,您需要递归地跟踪这条线索。

没有正确的方法可以告诉您引用的程序集的文件名。引用以程序集名称(名称、版本、区域性等)而不是文件名的形式存储在清单中。当 .NET 运行时需要加载引用的程序集时,它会使用各种搜索来查找它,并且这些搜索的结果可能因环境而异。当然,例如,如果您只是在开发计算机上查找程序集,这对您来说可能不是问题。

解析程序集引用的技术包括搜索已加载的任何程序集、在全局程序集缓存中查找、在应用程序目录中查找、根据应用程序配置文件或发布者策略进行重定向等。 Google 搜索 MSDN 中的文章“运行时如何定位程序集”以了解更多详细信息。此外,您的应用程序可以注册通过处理 System::AppDomain::AssemblyResolve 事件来执行自己的引用解析。

I don't know of any tools to do this automatically for you, but I can outline the steps any tool (or you) would have to follow.

Each assembly contains a manifest. The manifest lists the names and versions of all other assemblies that the current assembly depends upon. At its simplest you'd need to follow this trail recursively.

There's no correct way to tell you the filenames of the referenced assemblies. References are stored in the manifest as assembly names (name, version, culture, etc.) and not as filenames. When the .NET runtime needs to load a referenced assembly it uses various searches to find it, and the result of these searches may vary from environment to environment. Of course, this might not be a problem for you if you're just looking for the assemblies on your development machine, for example.

Techniques for resolving assembly references include searching any assemblies already loaded, looking in the Global Assembly Cache, looking in the application directory, redirecting based on application configuration files or publisher policies, and others. Google for the article "How the Runtime Locates Assemblies" in MSDN for more details. In addition, your application can register to do its own reference resolution by handling the System::AppDomain::AssemblyResolve event.

凯凯我们等你回来 2025-01-01 06:48:36

这段代码可以很好地找到所有的引用。 “temp”将是它跟踪的所有引用的转储。

    private void PerformReferenceAnalysis()
    {
        StringBuilder builder = new StringBuilder();
        HashSet<string> loadedAssemblies = new HashSet<string>();
        PerformReferenceAnalysis(System.Reflection.Assembly.GetExecutingAssembly(), builder, string.Empty, loadedAssemblies);
        string temp = builder.ToString();
    }

    private void PerformReferenceAnalysis(System.Reflection.Assembly assembly, StringBuilder builder, string leadingWhitespace, HashSet<string> loadedAssemblies)
    {
        if (builder.Length > 0)
        {
            builder.AppendLine();
        }
        builder.Append(leadingWhitespace + assembly.FullName);
        System.Reflection.AssemblyName[] referencedAssemblies = assembly.GetReferencedAssemblies();
        foreach (System.Reflection.AssemblyName assemblyName in referencedAssemblies)
        {
            if (loadedAssemblies.Contains(assemblyName.Name))
            {
                continue;
            }
            loadedAssemblies.Add(assemblyName.Name);
            System.Reflection.Assembly nextAssembly;
            try
            {
                nextAssembly = System.Reflection.Assembly.ReflectionOnlyLoad(assemblyName.FullName);
            }
            catch (Exception)
            {
                try
                {
                    nextAssembly = System.Reflection.Assembly.ReflectionOnlyLoad(assemblyName.Name);
                }
                catch (Exception)
                {
                    nextAssembly = null;
                }
            }
            if (nextAssembly != null)
            {
                PerformReferenceAnalysis(nextAssembly, builder, leadingWhitespace + "| ", loadedAssemblies);
            }
        }
    }

This code will do a fairly good job at finding all the references. "temp" will be a dump of all the references it traced.

    private void PerformReferenceAnalysis()
    {
        StringBuilder builder = new StringBuilder();
        HashSet<string> loadedAssemblies = new HashSet<string>();
        PerformReferenceAnalysis(System.Reflection.Assembly.GetExecutingAssembly(), builder, string.Empty, loadedAssemblies);
        string temp = builder.ToString();
    }

    private void PerformReferenceAnalysis(System.Reflection.Assembly assembly, StringBuilder builder, string leadingWhitespace, HashSet<string> loadedAssemblies)
    {
        if (builder.Length > 0)
        {
            builder.AppendLine();
        }
        builder.Append(leadingWhitespace + assembly.FullName);
        System.Reflection.AssemblyName[] referencedAssemblies = assembly.GetReferencedAssemblies();
        foreach (System.Reflection.AssemblyName assemblyName in referencedAssemblies)
        {
            if (loadedAssemblies.Contains(assemblyName.Name))
            {
                continue;
            }
            loadedAssemblies.Add(assemblyName.Name);
            System.Reflection.Assembly nextAssembly;
            try
            {
                nextAssembly = System.Reflection.Assembly.ReflectionOnlyLoad(assemblyName.FullName);
            }
            catch (Exception)
            {
                try
                {
                    nextAssembly = System.Reflection.Assembly.ReflectionOnlyLoad(assemblyName.Name);
                }
                catch (Exception)
                {
                    nextAssembly = null;
                }
            }
            if (nextAssembly != null)
            {
                PerformReferenceAnalysis(nextAssembly, builder, leadingWhitespace + "| ", loadedAssemblies);
            }
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文