确定DLL在C#程序中使用的文件列表 [英] Determine the list of files which DLL uses in C# program

查看:93
本文介绍了确定DLL在C#程序中使用的文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将尝试描述我的问题...例如我在项目(C#)中加载了General.dll,使用

I will try to describe my question... I load, for example, "General.dll" in my project (C#) using

//load "General.dll"
dllHandle = LoadLibraryEx(generalPath, IntPtr.Zero, LOAD_WITH_ALTERED_SEARCH_PATH);

[DllImport("kernel32.dll")]         
private static extern IntPtr LoadLibraryEx(string dllToLoad, IntPtr reserved, uint flags);

[DllImport("General.dll")] ...

如果我使用General.dll需要Gif.dll的方法,我需要将Gif.dll复制到General.dll文件夹(如果我不使用这种方法我不能复制 Gif.dll)。

If I use a method from "General.dll" which requires "Gif.dll" I need to copy "Gif.dll" to the folder with "General.dll" (if I do not use such method I can do not copy "Gif.dll").

如果我使用General.dll中使用Dutch语言的方法,我需要将Dutch.amd复制到文件夹与General.dll。

If I use a method from"General.dll" which uses "Dutch" language, I need to copy "Dutch.amd" to the folder with "General.dll".

例如,我已经写了一些使用General.dll不同方法的代码。如何确定文件夹中有哪些文件与General.dll我可以删除?

For example, I have wrote some code which uses different methods from "General.dll". How to determine which files from the folder with "General.dll" I can delete?

我可以使用Visual Studio吗?例如,在VS中编译我的代码,找出在运行时使用哪些文件,并只复制这些文件。

Can I do this using Visual Studio? For example, compile my code in VS, find out which files were used during runtime and copy only these files.

谢谢!

推荐答案

通常,任何可再发行组件都将包含部署指导原则,其中说明必须部署哪些文件,必须部署哪些文件以及必须进行的任何注册。我强烈建议您查看 general.dll 的文档(如果存在)。

Typically, any redistributable component will include deployment guidelines which state what files must be deployed, where they must be deployed to, and any registration that must occur. I highly recommend you review the documentation for general.dll, if it exists.

如果 general.dll 是您自己的工作,然后查看代码以查找所有引用的文件和程序集。如果它太大了,一个体面的启发式可能是运行过程监视器同时使用组件监视文件和注册表访问。许多安装程序创作工具使用类似的技术来检测依赖关系。

If general.dll is your own work, then look at the code to find all referenced files and assemblies. If it is too voluminous, a decent heuristic might be to run Process Monitor while using the component to monitor file and registry access. Many installer authoring tools use similar techniques to detect dependencies.

如果您没有相关组件的文档或源代码,可以使用 dumpbin / dependents Dependency Walker / depends.exe ,甚至只是 strings 来查找导入声明。不过,请注意,此列表不是排他的,可能会有条件地放弃关键文件(仅限某些机器类型,文化或其他方式)。

If you do not have documentation nor source code for the component in question, you can use dumpbin /dependents, Dependency Walker / depends.exe, or even just strings to find the imports declared. Beware, however, that this list is not exclusive, and may leave out critical files loaded conditionally (only on certain machine types, cultures, or otherwise).

这篇关于确定DLL在C#程序中使用的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆