2

I have a solution consisting of three Projects, both A and B are executable and depend on C. C has some file resource that is needed by whichever of the two is executed. The file needs to be copied into the output folder of both projects. Why? Because both use a library that expects the file to be in the folder AppDomain.CurrentDomain.BaseDirectory which is where you launch the executable from. So copying it to the output folder of C has no effect. Copying it via xcopy in an after build step seems a bit too fragile, since I don't know where exactly the output folders will be (debug/x64/bin/...)

For example, if you reference/depend on a DLL, that DLL gets copied to the output dir of the project that is being launched. But unfortunately my file is not a DLL and thus cannot be added as project "reference" so this doesn't work.

hunger
  • 413
  • 1
  • 4
  • 12

1 Answers1

1

In VisualStudio in the Properties pane of the file you can set "Build Action" to "Content" and "Copy to Output Directory" to "Copy always" or "Copy if newer". Now if either your project A or B have project C set as a project reference the file will also be put in the build folder of projects A and B.

properties output

Longoon12000
  • 774
  • 3
  • 13
  • That works! Unfortunately, now the file is in the output subfolder "resources" (as it is like that in project C) where it still isn't found. Can I make it so that the file is in the root output folder? – hunger Nov 21 '19 at 14:17
  • With https://stackoverflow.com/questions/18743907/visual-studio-how-to-copy-to-output-directory-without-copying-the-folder-stru it is now copied to the root. Thanks! – hunger Nov 21 '19 at 14:26