Copying Visual Studio project file(s) to output directory during build

Synetech picture Synetech · May 31, 2012 · Viewed 81.7k times · Source

When I build a Visual Studio project, the executable is written to the output directory specified in the projects Property Page.

I have a project that has some extra files (e.g., .ini file) that are used by the program.

How can I configure the project to copy the file to the output directory so that when the program runs, it has a copy of the other file in its CWD?

I checked the Property Page of the file and there was nothing useful other than an option to exclude it from the build (which is disabled), and the custom-build-tool command is empty (plus it is a plain-text file that does not need any processing).

Answer

Dmitry Pavlov picture Dmitry Pavlov · Jun 1, 2012

For copying a files to the output directory in Visual Studio 2003 you could use Post-Build event:

  1. Right click on the project->Properties
  2. Common Properties->Build Events
  3. Set Post-Build Event Command Line to:

    xcopy /y $(ProjectDir)my_file.ini  $(ProjectDir)$(OutDir)
    
  4. OK and build!