0

When you're adding a C# project reference (let's call it LibraryProject) to another C# project (MainProject) in Visual Studio, the assembly LibraryProject.dll gets copied automatically to MainProject output directory, enabling its use in MainProject without further user intervention. How to do it, if LibraryProject is a C++ project, in a reliable and project-independent way? - that is, without manually specifying post-build events to copy resulting DLL (which location is dependent on several other settings) to main project directory (which location is also dependent on some settings, and there may even be multiple runnable assemblies in a single solution [test projects, console tools etc.], either only some or all of them needing to access LibraryProject)?

Or, as explained on an example:

In my solution there's a C++ library project (MyCppLibrary), and a C# wrapper project for that library (MyCSharpWrapper). There's also a main C# project (MyCSharpApplication) and a C# unit test project (MyCSharpTests).

When I reference MyCSharpWrapper from wither MyCSharpApplication or MyCSharpTests, I want to have not only MyCSharpWrapper.dll, but also MyCppLibrary.dll copied to respective output directories (or made accessible in some other way) of MyCSharpApplication and/or MyCSharpTests. And I want it all to happen automatically, without having to set up post-build events on MyCSharpApplication or MyCSharpTests to copy the DLLs semi-manually.

EDIT: I'm not asking about how to call C++ code from C# - I'm aware of DllImportAttribute and how to use it. What I want to know how to instruct Visual Studio to automatically copy MyCppLibrary.dll to output directory, when MyCSharpWrapper is referenced from another project.

T.M.
  • 9
  • 2
  • as I remember the only way is to create a dll file and make a reference to it or to use dllimport sentence since the library in another language than c# – AnAs51993 Apr 12 '16 at 00:43

1 Answers1

0

If I understand the requirement, you would like to make sure that the C++ DLL gets copied to a location that is the output directory of the C# project, probably so that you can use the IDE debug directly.

This should be possible by simply specifying a common output folder (say, $(SolutionDir)\BuildRel) in the Project Properties for both the C# and C++ projects - https://msdn.microsoft.com/en-us/library/ms165410.aspx. That would drop all binaries in the same location and so runtime linking should work.

Vivek
  • 428
  • 2
  • 13