3

I have included some native DLLs that my project depends on into the project and set in their properties Build Action to content and Copy to Directory to Copy if newer.

I am now having the annoying behavior that the DLLs are sometimes not being copied to the output directory, when I build a project. The behavior appears to be, that when I select Build they are not being copied, but they are being copied when I select Rebuild. To make matters worse they are sometimes removed and I am not sure when (I believe before performing a normal Build).

So my question is: What am I doing wrong? I have also found people using the Post-Build event to copy the DLLs, so is my way not the correct way to do it?

Edit:

I forgot to mention that I have two projects (on which the project that I am building depends) with the same Dlls included, since they both depend on EmguCV, which uses the native OpenCV Dlls, which are the ones causing the trouble.

packoman
  • 1,230
  • 1
  • 16
  • 36
  • You shouldnt have to copy them manually. BTW, running a Clean will remote all binaries in the bin folder. Are these nuget packages? Does it not copy any dll's or just a few select ones? – Botonomous Aug 05 '16 at 13:49
  • I *think* that the problem is that you use both the `content` build action and the `Copy to directory` function. Both settings should copy the file to the output. Try to disable one of both? – Nitram Aug 05 '16 at 13:50
  • You are going to have to build for a while with the MSBuild verbosity set to detailed. When it goes wrong then the build trace will tell you why it didn't think that it needed to copy the file. Without that trace it is just blind guessing. – Hans Passant Aug 05 '16 at 13:56
  • Have you tried setting Copy to Directory to Always? – The Shooter Aug 05 '16 at 14:00
  • @TheShooter I tried that. – packoman Aug 05 '16 at 14:01
  • I forgot to mention that I am using the same Dlls from two sub-projects that in theory should both copy their versions of the Dlls to final output directory. Perhaps that could be a source of the error? – packoman Aug 05 '16 at 14:02
  • It can result in wrong version of dlls getting copied but not in not getting copied at all. – The Shooter Aug 05 '16 at 14:02
  • @TheShooter Thats what I thought. But they are identical versions that I keep in both projects, so that they are isolate from each other. Or rather: Self-contained – packoman Aug 05 '16 at 14:04
  • Try building individual projects (dependent on) couple of times and observe the behaviour. If there isn't a issue then try building the dependent project. As @HansPassant has mentioned in the Tools->Options set msbuild verbosity to detailed or diagnostic and see in the log where the trouble is. Remember diagnostic log is really big one so would take time to figure out everything. Would be heading home so wouldn't be able to see your messages. – The Shooter Aug 05 '16 at 14:10
  • I just found this: http://stackoverflow.com/questions/856278/why-the-native-dll-is-not-copied-to-the-output-directory Could it be related. I am still looking into the output of MSBuild. – packoman Aug 05 '16 at 14:27
  • 1
    @packoman Hi! It's one year on and I'm seeing exactly what you were. Did you ever manage to track down a problem that can be fixed? Or does it seem that this is just "working as intended"? If it's working as intended, did you find a workaround? I'm thinking a post-build event will be best, but that still sucks. –  Jun 19 '17 at 14:02

0 Answers0