如何以编程方式检查C ++ DLL文件和C#DLL文件,以引用调试DLLS来自动执行测试过程
我遇到这个问题太多次了,需要这样做是一种自动化的方法:
I have run into this issue too many times and need this to be an automated approach:
我有多个DLL文件不断被构建/更改,项目使用。
I have multiple DLL files that are constantly being built/changed that multiple projects use.
我创建了一个C#应用程序,用于检测DLL文件是否存在,并且如果不存在则警告操作员,并杀死程序。在这个C#应用程序中,我想要检查它是否是一个调试版本 - 换句话说,如果它运行在最终用户的计算机上,它将会崩溃。
I have created a C# application that detects if the DLL files are present and warns the operator if they are not and kills the program. In this C# application, I want it to also check to determine if it is a "debug" version - in other words it would crash if it ran on an end users computer.
现在我一直在搜索高低,找到一些可能的解决方案,但都是落伍。
Now I have been searching high and low and found a few possible solutions, but they all fall through.
Assembly.LoadFrom(string)
不适用于非托管代码。我可以使用它来测试受管理的DLL文件,但不是C ++的。
Assembly.LoadFrom(string)
does not work for unmanaged code. I can use this to test against the managed DLL files but not the C++ ones.
我以为我可以使用 Dependency Walker 或类似的程序在我的应用程序中运行,给我的程序集引用的数据,不幸的是, .exe
控制台只输出到一个文件(然后我必须读取每个文件并解析它为我的数据(非常密集的加上我必须包括 depends.exe
和我的项目中的DLL文件)),此外,它似乎没有输出我真正想要的数据(或至少我无法做到)。
I thought I might be able to use Dependency Walker or similar program to run within my application to give me the data of the assembly references, unfortunately, the depends.exe
console only outputs to a file (and then I would have to read in each file and parse it for my data (very intensive plus I have to include the depends.exe
and DLL files in my projects)), furthermore, it doesn't seem to output the data I really want (or at least I wasn't able to make it).
还尝试转储,但我似乎不能得到它在我的机器上运行。
Also tried dumpbin, but I can't seem to get it to run on my machine.
我还发现了一些应该给我Dependency Walker的来源的链接。不幸的是,他们都死了。我不会认为这是一件很难做的事情,但无论如何,我都非常难以确定如何自动化。
I also found some links that were supposed to give me the source for Dependency Walker. Unfortunately they all turned up dead. I wouldn't think this is that hard of a thing to do, but for whatever reason I am having quite the difficulty figuring out how automate this.
一些源链接对我有帮助,但是他们都没有解决非托管汇编数据的问题。
Some source links that have been helpful to me, but none of them have solved the issue with unmanaged assembly data.
如何自动化集成测试 (Stack Overflow)
How to automate integration testing? (Stack Overflow)
以编程方式检测发布/调试模式.NET) (Stack Overflow)
Programmatically detecting Release/Debug mode (.NET) (Stack Overflow)
如何检测应用程序所需的DLL? (Stack Overflow)
How do I detect the DLLs required by an application? (Stack Overflow)
如果您知道所有DLL的名称(例如,您运行Dependency Walker),您只需使用LoadLibrary来检查非托管DLL。
If you know the names of all the DLLs (because, for example, you ran Dependency Walker) you can just use LoadLibrary to check for unmanaged DLLs.
[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, uint dwFlags);
const UInt32 DONT_RESOLVE_DLL_REFERENCES = 0x00000001;
const UInt32 LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
const UInt32 LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008;
[DllImport("kernel32.dll")]
static extern bool FreeLibrary(IntPtr hModule);
[DllImport("kernel32.dll")]
static extern UInt32 GetLastError();
void CheckUnmanagedDll(string DllName)
{
IntPtr hModule = LoadLibrary(DllName);
if (hModule.Equals(IntPtr.Zero))
MessageBox.Show("Can't find " + DllName);
FreeLibrary(hModule);
}