I have run into this issue too many times and need this to be an automated approach:
I have multiple DLL files that are constantly being built/changed that multiple projects use.
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)
does not work for unmanaged code. I can use this to test against the managed DLL files but not the C++ ones.
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.
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.
Use
GetModuleHandle
to check for the presence of a DLL with the given name. If you want to know if it's a debug version or not, then you need to compile that information into the EXE and check for it somehow. "Debug" vs. "Release" is not a concept built-in to PE format; it's just a set of compile options. Many people put a flag in the version information to indicate whether it's an internal vs. public release.P/Invoke reference for GetModuleHandle
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.