Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying a non-.NET dependency in Visual Studio

I'm calling a non-.NET dll from my project using P/Invoke, meaning that the .dll must always be present in the .exe's directory.

Is there any way to tell Visual Studio of this dependency, so that it will automatically copy the .dll to the output directory when compiling, and will automatically include the .dll in the setup? Or do I have to do this manually?

like image 596
Grokys Avatar asked Sep 24 '08 10:09

Grokys


3 Answers

You can simply add the .DLL to your project.

Select the Properties pane for that file and set Build Action to Content and Copy to Output Directory to Copy if newer.

like image 165
Magnus Johansson Avatar answered Nov 06 '22 12:11

Magnus Johansson


You can copy/link this file(s) to the project, and in properties windows set "Build Action" to "None" and "Copy to Output Directory" to "Copy if newer" or "Copy always".

Or you can use a "Pre-Build Events" & "Post-Build Events" where you can specify any batch scripts.

I prefere the second option, because this way is more flexible than the first.

Also you can modify a MSBuild file and add a task for copy the file(s).

like image 39
TcKs Avatar answered Nov 06 '22 13:11

TcKs


I think one problem with just adding a .DLL to the project is that you may need different versions of a DLL for debug and release builds. You'd think you can add both debug and release versions of the DLL to the file, and based on configurations, exclude the inappropriate one, but I couldn't find a way to do that. I'm using Visual Studio 2010. I am positive this worked in the old days with VS6.

like image 2
zumalifeguard Avatar answered Nov 06 '22 12:11

zumalifeguard