Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output content file to specific folder while building project

I have VS 2012 project with structure like this:

Project
   Folder1
      file.xml
      schema.xsd
      code.cs
   Folder2
      code1.cs
      code2.cs

I set Copy to output directory property of file.xml and schema.xsd to Copy always and want to output them to the same folder where assemblies outputed (bin\Debug) but they always copied to folder bin\Debug\Folder1. Is there a way to achieve my goal without moving files to the root of the project?

like image 390
tsionyx Avatar asked Oct 04 '12 04:10

tsionyx


1 Answers

I recommend you do this with a Post-built event script. It's not as hectic as it sounds, and gives you loads of flexibility.

  • Right-click on your project and select Properties.
  • Go to the Build Events tab and click Edit Post-build...

(See screenshots below)

You can now specify shell commands to be executed after each successful build of your project. The following achieves the example in your question:

copy "$(ProjectDir)Folder1\file.xml" "$(TargetDir)"
copy "$(ProjectDir)Folder1\schema.xsd" "$(TargetDir)"

$(ProjectDir) and $(TargetDir) are macros which insert the respective values relevant to your project. You can select and insert macros from the macro menu in the edit window.

The quotes are included above, because your ProjectDir and TargetDir might resolve to full paths that include spaces, and that will break the copy command if the spaces aren't there.

Opening Porject Properties

Editing Post Build

like image 124
Pieter Müller Avatar answered Sep 22 '22 10:09

Pieter Müller