Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Visual Studios build system to understand unmanaged dependencies of managed dlls?

When building managed code Visual Studio correctly (and recursively) copies dlls of referenced managed projects to the output folder of the project being build.

However, if one the of those references is a managed DLL that depends on unmanaged dlls then these unmanaged DLLs are not copied to the output folder, even though their corresponding projects in the same solution and are listed as dependencies of the managed DLL.

I realize that this problem can be resolved by having all projects use the same output folder. We already do that for most projects, but we prefer to keep unit test output folders separate, causing the above issue for unit tests that use a managed Dll with unmanaged dependencies.

The solution we are using right now is a pre-build event to copy the necessary DLLs but this wastes time and is error-prone as it needs to be repeated for every project that uses the managed DLL.

I would therefore like to know if there is a way to get the build system to understand that it should always copy the unmanaged dependencies of the managed DLL whenever it decides to copy the managed DLL?

like image 533
Ziphnor Avatar asked Dec 30 '09 13:12

Ziphnor


People also ask

How to check project Dependencies in Visual Studio 2019?

On the Project menu, choose Project Dependencies. The Project Dependencies dialog box opens. On the Dependencies tab, select a project from the Project drop-down menu. In the Depends on field, select the check box of any other project that must build before this project does.

What is project dependency in Visual Studio?

When a project consumes executable code generated by another project, the project that generates the code is referred to as a project dependency of the project that consumes the code. Such dependency relationships can be defined in the Project Dependencies dialog box.


1 Answers

One workaround seems to be to add another node to the managed DLL project, naming the unmanaged DLL and setting the Build Action = "None", and Copy to Output Directory = "Copy if Newer".

Edit: For building a C++/CLR project, I think this would work:

Add the node, and set its build tool to Custom Build Tool. Then, in the Custom Build Step page, set the Command to copy $(InputPath) $(OutDir) and the Outputs to $(OutDir)\$(InputFileName). Looks like that should work.

like image 105
Tarydon Avatar answered Sep 19 '22 20:09

Tarydon