Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force external files to be copied to bin folder on publish

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.

like image 428
Alex AIT Avatar asked Sep 24 '12 10:09

Alex AIT


People also ask

What is Copy to Output Directory?

"Copy to Output Directory" is the property of the files within a Visual Studio project, which defines if the file will be copied to the project's built path as it is. Coping the file as it is allows us to use relative path to files within the project.

What is Binn folder?

Bin is short for binary. It refers to a directory that contains executable commands for your application. Access to the Bin folder can help you change license and configuration files.


2 Answers

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.

like image 147
Alex AIT Avatar answered Oct 13 '22 16:10

Alex AIT


It's common to have a lib folder in either your solution or workspace to put your third party dlls within. You would then add a reference to this location from your project and ensure this location is under source control.

You could also look at using NuGet to package this for you, which uses a solution level packages folder automatically.

like image 41
dove Avatar answered Oct 13 '22 17:10

dove