Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly reference a dll in Visual Studio 2010?

I have a solution that contains a C++ DLL project, and a C# project that will use this DLL (by using PInvoke).

The dll is being built to the x64/Release folder in my solution folder, which makes sense, because that way the C# project doesn't have to poke into the DLL project's folders.

I wonder what would be the correct way to reference it now though. Right now, the DLL project is a dependency of the C# project. My intuition told me that that should have been enough, but the C# project says it cannot find the DLL.

Should I just add the .dll file as a reference too? I thought this might work now but break things in the long run when project settings might get changed around.

like image 201
Lee White Avatar asked Apr 03 '13 07:04

Lee White


2 Answers

I've answered a similar question before. So I don't repeat the text here.

You might want to take a look of:

  • When using open source libraries, should we compile against the source or the binaries?

Wish that helps.

like image 77
Ken Kin Avatar answered Oct 06 '22 00:10

Ken Kin


Usually in such situations I configure my solution such that all projects compile to $(SolutionDir)bin\$(Configuration). The binaries are then located the same way as in production mode and DLLs may be easily used.

As for keeping the latest version of DLL, remember, that you may set a dependency, such that if anything changes in DLL, it will be rebuilt prior to building your assembly / application.

Yet another way is to use build events (prebuild and postbuild) to copy your DLL into appropriate folder.

like image 28
Spook Avatar answered Oct 05 '22 23:10

Spook