Track DLL dependencies for updating the native C ++ DLL to .NET.

I have a C ++ DLL (no code) that I want to open for .NET applications.

Having studied all the parameters that I / know / can find (COM, P / Invoke, SWIG, etc.), I am writing a .NET class library (in C ++ / CLI). Now the resulting DLL (class library) also requires the original DLL and its dependencies. My problem is to automatically track such things, so applications using the shell do not need to track other (native) DLLs (especially if the source DLL is developing a new dependency).

To be more precise (and have something specific to discuss), I'm trying to wrap cmr , so I'm writing MR , a class library (which depends on cmr , of course). cmr depends on PNL , OpenCV and others. When I tried to add a reference to MR in the project (C #), Visual Studio (2005 SP1) simply copied MR.DLL , leaving all the dependent data and then complaining (throwing a FileNotFoundException about missing modules). Manual copying cmr , PNL , etc. The bin directory fixes the problem.

Without much ado, my question is: is there a way for .NET applications to add only a link to a single DLL, and everything just works?

I made my way through Google and SO, to no avail ...

EDIT : mergebin seems the closest to what I'm looking for, but it can combine .NET DLLs with one native DLL. Too bad that you cannot combine your own DLLs.

+4
source share
4 answers

You can take a look at mergebin , a tool that allows you to combine unmanaged and managed DLLs into one assembly. System.Data.SQLite takes this approach.

+6
source

I am currently having a very similar problem.

One big step, too, for my purpose, was to copy Native.DLL to the output directory at a previously built stage in a C ++ / CLI project and add the linker option

 /ASSEMBLYLINKRESOURCE:"$(OutDir)\Native.dll" 

This writes to the resulting assembly that there is a "Native.dll" file that belongs to the assembly. Now all projects that reference the project / assembly will also copy Native.dll! (It should also get into the GAC, if you put you on the assembly - I did not check this).

Well, you still need to add all the dependencies of native.dll. I also don’t know if the built-in DLL was found at runtime if you load the assembly via Assembly.LoadFrom () from a completely different path (this is what I have to solve for my problem, because our C ++ / CLI assembly is required by the developer Visual Studio).

Hope this helps you a little for you.

EDIT:

Further research showed that Wrapper.DLL always finds a native .DLL ... which is good. The bad news is that Visual Studio Designer copies the necessary assemblies to a temporary directory (somewhere inside the user directory) when the form is opened. When it copies assemblies, it ignores related resources and this is the native .DLL!

+2
source

It looks like you have two problems:

  • How to copy native code dlls before running assembly
  • How to dynamically determine the source code dependencies that you need to copy if they change.

For 1) you can use the pre-build step in your C # project to call a custom utility to copy the correct files.

Looks like 2) was already here on a stack overflow .

0
source

Well, you can simply add commands to automatically copy the necessary DLLs to the correct output directory as part of the build process. This is done in Visual Studio by going to the project properties.

Project β†’ MyProjectName Properties ... β†’ Assembly Events

Add the commands to copy the files you need into $ (TargetPath), and you're done.

Another option is to simply set the current working directory of your project (when you use it only from Visual Studio) to be the directory in which all the DLL files are located. You still have to manually copy the files when running the program from the outside, but this will simplify the development process.

0
source

All Articles