How to reference dll in Visual Studio 2010?

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

The dll is created in the x64/Release folder in the folder with my solution, which makes sense, because in this way the C # project should not insert DLLs into the project folders.

Interestingly, that would be the right way to refer to it now. Right now, a DLL project is a dependency of a C # project. My intuition told me that this should be enough, but the C # project says that it cannot find the DLL.

Should I just add the .dll file as a link? I thought this might work now, but ultimately break things when project settings can change.

+7
source share
3 answers

Usually in such situations, I configure my solution so that all projects make up $(SolutionDir)bin\$(Configuration) . Then the binaries are located in the same way as in production mode, and DLLs can be easily used.

As with the latest version of the DLL, remember that you can install the dependency, so that if something changes in the DLL, it will be restored before the assembly of the assembly / application.

Another way is to use build events (prebuild and postbuild) to copy your DLL to the appropriate folder.

+1
source

I answered a similar question before. Therefore, I do not repeat the text here.

You might want to see:

Wish it helps.

+2
source

You cannot add an unmanaged DLL as a reference in a managed project. The DLL must be located either in the executable folder or in any other folder of the PATH system.

It is best to use the Event after Build so that VS copies the DLL to the folder where it is needed every time it is rebuilt.

+1
source

All Articles