I have two projects with the full source code, one in C# and the other in C in one VS 2012 solution. The C# code is calling the C .dll via PInvoke.
I set the dependency on the solution level to tell the solution to build the C project before it builds the C# project.
Ideally, I would like to have the generated C .dll next to my executing C# dll, so I would refer to it by its naked name from my DllImport
. However, this is not easy given that another project that is using my C# project will not copy the C .dll across. This problem would not exist if all my projects are .NET as MS Build will copy the .dll to the host.
Are there any best practices or a magical VS option, that I am missing, to make the C .dll gets copied across in the same way that other .NET assemblies do?
This question is marked as a duplicate but it is not. The question referred to:
- It is talking about 3rd party .dlls, this one is about own project within the same solution.
- The accepted answer to that question doesn't take into consideration copying debug to debug and release to release.
- The accepted answer doesn't show how to copy through a chain of dependencies (C# -> C# -> C ).
I just found a solution which was inspired by https://stackoverflow.com/a/13944692/157017 which solves this specific situation.
<ItemGroup>
<Content Include="$(SolutionDir)$(Platform)\$(Configuration)\MyCProject.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>