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

buildprojects-and-solutionsvisual studiovisual-studio-2003

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).

Best Answer

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!