Search code examples
.netvisual-studio-2012rebuild

Why VS 2012 removes files from my destination directory?


I have seen answers to similar questions but I still don't understand this... I have scripts that place all dependencies into a common BIN directory, which is outside all the projects directories.

  • solution.snl
  • BIN
  • ProjectAFolder
  • ProjectBFolder

All projects reference everything from BIN and they build into BIN. This way builds are faster and SO MUCH CONFUSION is avoided, among many-many other benefits. But why the heck VS removes some unreferenced files from bin?! I have a ThirdParty.dll that references other files (so dlls have to be in the same folder with ThirdParty.dll). When I rebuild these other files are deleted! What a bright idea! Or is it a bug?

My build complains like so if I make the files read only: 43>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(3969,5): warning MSB3061: Unable to delete file "C:\Projects\GITBranches\trunk1\EDA\bin\tibrv.dll". Access to the path 'C:\Projects\GITBranches\trunk1\EDA\bin\tibrv.dll' is denied.

and this is the line in Microsoft.Common.targets that tries to do this:

<!-- Delete the orphaned files. -->
<Delete
    Files="@(_CleanOrphanFileWritesInIntermediate);@(_CleanOrphanFileWritesInOutput)"
    TreatErrorsAsWarnings="true">

  <Output TaskParameter="DeletedFiles" ItemName="_CleanOrphanFilesDeleted"/>

</Delete>

Does anyone know how I can win?

Thank you


Solution

  • I think your best bet is to have third party files stored in a separate directory, e.g. A Lib directory.

    Then you can copy them to your bin directory as part of a pre build event perhaps?