How do I detect the DLLs required by an application?

后端 未结 7 853
一生所求
一生所求 2020-11-30 11:40

In a nutshell: I want to do the same thing \"Dependency Walker\" does.

Is there any Win32 API function which can enumerate the dependencies of a EXE and/or DLL file?

相关标签:
7条回答
  • 2020-11-30 12:30

    You can write a console app to wrap this up, create a PowerShell script with it or, like I usually end up doing since I only have to do it once in a blue moon, add the following to your code for a quick check:

        private static HashSet<string> ReferencedAssemblies = new HashSet<string>();
    
        ...
        OutputDependencies(Assembly.GetAssembly(typeof(Program)), 0);
        ...
    
        static void OutputDependencies(Assembly assembly, int indent)
        {
            if (assembly == null) return;
    
            Console.WriteLine(new String(' ', indent * 4) + assembly.FullName);
            if (!ReferencedAssemblies.Contains(assembly.FullName))
            {
                ReferencedAssemblies.Add(assembly.FullName);
    
                foreach (var childAssembly in assembly.GetReferencedAssemblies())
                {
                    OutputDependencies(Assembly.Load(childAssembly.FullName), indent + 1);
                }
            }
        }
    
    0 讨论(0)
提交回复
热议问题