C # / C ++ in the same solution - DllImport does not find DLL

I have a solution with a C ++ dll project and a C # project that uses it. The problem is that the C ++ project build path is in the solution folder, and C # is in the project bin folder (each of them is embedded in debug / release), so DllImport does not find them.
Is there a standard way to fix this?

+8
c ++ c # visual-studio-2010 interop dllimport
source share
1 answer

The way you should do this is to set the build path for both projects to the same bin directory ... preferable for a solution, not a project. Then just create all the projects in this folder. You can change this from the project settings.

Another method is to use a post-build step for a C ++ application that copies the DLL to the C # project folder. This way you are not actually changing any paths. You just copy the DLL. Be careful, because when you clean up your C ++ file project, you can still have a copy in the C # projec'ts bin directory, leaving you scratching your head about why things are not going as expected.

Alternatively, you can deploy the C ++ DLL to the system path (also as part of the post-build phase), but you will have the same problems as above.

For debugging, I would recommend them in the order presented.

+6
source share

All Articles