-3

I have a folder that lives in my C# project that I want to be copied to bin after every release build in VS2013. How can I specify additional items to be copied to bin?

The folder is in another project in the same solution.

For example

SoluationA

     ProjectA

     ProjectB
          FolderC

I want to copy FolderC to the bin of ProjectA

PositiveGuy
  • 46,620
  • 110
  • 305
  • 471
  • 1
    who in the world voted this down. It's a very clear question. This is something I believe you should be able to do with a csproj am I right? – PositiveGuy Oct 20 '14 at 18:36
  • 5
    What did your search "copy folder to bin" yield? [Copying files into the application folder at compile time](http://stackoverflow.com/questions/747941/), [Copy file(s) from one project to another using post build event…VS2010](http://stackoverflow.com/questions/11001822/), [Visual Studio 2008 - Moving files at build to bin/](http://stackoverflow.com/questions/4998974/), [How to include other files to the output directory in C# upon build?](http://stackoverflow.com/questions/16785369/) and so on. This question shows no research effort for a trivial and common question, no need for pity-upvotes. – CodeCaster Oct 20 '14 at 18:37
  • 8
    @CoffeeAddict Downvote as, per the downvote mouseover, "this question does not show any research effort". – admdrew Oct 20 '14 at 18:37
  • It should be included as part of the build. Is the folder empty? – Arian Motamedi Oct 20 '14 at 18:37
  • @vc74: You don't actually get that option on a folder. – Matt Burland Oct 20 '14 at 18:40
  • MODIFIED please review – PositiveGuy Oct 20 '14 at 18:52

1 Answers1

4

If it actually resides in the project (that is, the files are included in the .vcproj file); then you just need to set their "Copy to Output Directory" setting to "Copy if Newer" or "Copy Always". The directory structure will be maintained.

If you need to just create a directory, use MKDIR in a post-build event to create it.

If you need to copy an existing folder in, use xcopy in a post-build event to copy it over.

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
  • 2
    Note: you must do the first solution to the files in the folder, you can't set it on the folder itself. If you set a file to one of the two copy options it will retain the folder structure leading up to the project root like the answer says. – Scott Chamberlain Oct 20 '14 at 18:41
  • 2
    @ScottChamberlain Yes; if you need an *empty* directory, you are effectively stuck with the MKDIR post-build event option. – BradleyDotNET Oct 20 '14 at 18:43
  • the folder resides in a different project in the same solution – PositiveGuy Oct 20 '14 at 18:46
  • it's not empty, it contains files – PositiveGuy Oct 20 '14 at 18:48
  • 1
    @CoffeeAddict You put it as a line in the "Post-Build Events" box in the project settings. Make sure you use relative paths and the environment variables, or things get hairy fast. – BradleyDotNET Oct 20 '14 at 18:48
  • it resides in a differ project same solution. See updated post – PositiveGuy Oct 20 '14 at 18:53
  • so not sure how I'd do this as this xcopy is for the current project copy $(ProjectDir)\Configuration\* $(ProjectPath)\$(OutDir) – PositiveGuy Oct 20 '14 at 18:53
  • @CoffeeAddict You need a relative path in that instance. If I recall correctly, its relative from the solution root; so it would be xcopy Configuration\FolderC $(ProjectPath)\$(OutDir) If its the project root, ..\Configuration--- – BradleyDotNET Oct 20 '14 at 18:56
  • thanks I figured out another way too. How do you go up one level in the relative pagth? I tried adding a .. for example copy ..\$(ProjectDir)\Company.ProjectToCopyFromName\FolderToBeCodpied\* $(ProjectPath)\$(OutDir). This will work if I can just go up one level... $(ProjectDir) is including the project I'm copying to in the path and I don't want that – PositiveGuy Oct 20 '14 at 18:59
  • @CoffeeAddict You'll have to hardcode the other project name, as it doesn't exist as an environment variable. Perhaps we should chat to resolve your confusion? – BradleyDotNET Oct 20 '14 at 19:02
  • sure forgot about the chat, where do you start it? – PositiveGuy Oct 20 '14 at 19:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63363/discussion-between-bradleydotnet-and-coffeeaddict). – BradleyDotNET Oct 20 '14 at 19:09
  • this works copy $(SolutionDir)ProjectB\FolderC $(SolutionDir)ProjectA\$(OutDir) – PositiveGuy Oct 20 '14 at 20:30
  • thanks all! I didn't know the syntax well so it took me longer and with your help – PositiveGuy Oct 20 '14 at 20:37