简体   繁体   中英

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.

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

You might want to take a look of:

Wish that helps.

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.

You can not add an unmanaged DLL as reference in a managed project. The DLL needs to reside either in the executable's folder or in any other folder of the system's PATH.

The best way is to use a "Post Build Event" to have VS copy the DLL into the folder where it is needed every time it is rebuilt.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM