My solution is primarily C#, but I have one C++ project that creates a DLL which my C# code calls. Here's the layout:
[Edited: there are two levels of indirection, which causes the problem]
We'll call the solution MySolution. It has four projects:
MySolution MyCppDll (creates an unmanaged DLL) MyCSharpWrapper (Managed wrapper for the unmanaged DLL) MyCSharpLibrary (Contains classes that access the wrapper) MyCSharpProgram (Creates classes from MyCSharpLibrary)
I have the dependencies set up correctly so that MyCppDll is compiled first, then the wrapper, the library, and the program. However, when building within the IDE, the output of MyCppDll isn't copied to the output directory of MyCSharpLibrary.
I can get around that problem by creating a post-build step for MyCSharpLibrary, making it copy MyCppDll.dll to the MyCSharpLibrary\bin\Debug (or \Release) directory.
But then when MyCSharpProgram is compiled, it gets the files associated with the wrapper and the library, but it doesn't get the DLL. Again, I could create a post-build step to do it, but that's less than ideal, for a couple of reasons.
The real solution has several dozen projects, many of which reference MyCSharpLibrary. Creating a post-build step for each one is, as you can imagine, tiresome and error-prone. And every time I add a new project that references that assembly, I'll have to create another post-build step.
And it shouldn't be necessary. When I build that solution from the command line, the DLL is copied from the MyCSharpLibrary directory as expected. That is, building from the IDE, the directory MyCSharpProgram\bin\Debug contains MyCSharpProgram.exe, MyCSharpLibrary.dll, MyCSharpWrapper.dll (plus the associated .pdb files). But if I build from the command line (using MSBuild), the directory contains all that AND MyCppDll.dll.
Has anybody else run into this problem? I'm using Visual Studio 2008 and haven't yet upgraded to SP1.
[Edit - The problem appears to be that the files aren't copied unless there is a direct reference from the Program project to the Wrapper project. That is, if I add a reference to MyCSharpWrapper in the MyCSharpProgram project, then the DLL is copied. Again, this only happens in the IDE. It works fine without that reference when building from the command line.]