Force external files to be copied to bin folder on publish

Alex AIT picture Alex AIT · Sep 24, 2012 · Viewed 14.9k times · Source

I have a web application project that references a third party assembly, which in turn uses some native dlls that it needs to find at runtime. Because of that, I wanted to add these dlls to the bin folder of the project, so that they can definitely be found.

However, if I add the files to the project in /bin/, select "copy to output", the files are compiled and published into /bin/bin. Adding them to the root folder works, but can hardly be the right solution.

Adding them to the build target "AfterBuild" has no effect when publishing (e.g. "build deployment package")

It also has to work when building the solution via TFS, where the MSBuild target _CopyWebApplicationLegacy is invoked.

Answer

Alex AIT picture Alex AIT · Sep 24, 2012

The solution was a combination of the things I had tried already:

  • Include the "Bin" folder in the project
  • Add the needed files (I added them as a link due to our development structure)
  • Set the following properties: "Build Action = Content" and "Copy to Output = Do Not Copy"

The files are now copied to the bin folder when publishing, even when automating the builds on TFS.

The component that needed this was GdPicture, which uses a couple of native DLLs during runtime.