0

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>
Community
  • 1
  • 1
Adam
  • 3,872
  • 6
  • 36
  • 66
  • Thank you. While some of the answers to that question apply to this question, but the question itself is asking about 3rd party dlls and not own project within the same solution. – Adam May 05 '13 at 08:12
  • That doesn't change anything, you still have to use build events, there's nothing specific for native projects in the same solution. – Simon Mourier May 05 '13 at 09:06
  • It is a shame that you closed this answer even though it is a different case and has a different solution. As this solution is supposed to work even if the solution configurations have changed. – Adam May 05 '13 at 09:26
  • Grab more points and vote for reopen: http://meta.stackexchange.com/questions/36415/how-do-you-reopen-a-closed-question – Simon Mourier May 05 '13 at 09:35
  • I found a solution and I posted it as part of my question to help somebody else who has the exact problem. I am personally no longer interested in having an answer, because I already got one. And I am frustrated by the fact that all these admins marked it as duplicates just because they saw you marking it as such and may have quickly skimmed it. – Adam May 05 '13 at 09:40
  • I don't know whether or not this should be a duplicate, but be aware that the quality of the answers at the other question is not relevant when determining whether or not a question is a a duplicate. All that matters is whether or not the two questions are the same. I'm not casting any judgement on the voting, just letting you know how things work. – David Heffernan May 05 '13 at 18:21
  • @DavidHeffernan as that question is asking something different, an SO searcher might not consider it. Anyway, I got my answer and updated my question to help searchers. – Adam May 05 '13 at 23:19

0 Answers0