Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 824
Synetech Avatar asked May 31 '12 03:05

Synetech


People also ask

What does Copy to Output Directory do?

"Copy to Output Directory" is the property of the files within a Visual Studio project, which defines if the file will be copied to the project's built path as it is. Coping the file as it is allows us to use relative path to files within the project.

How do I change the build output directory in Visual Studio?

To place all solution outputs in a common directory Click on one project in the solution. On the Project menu, click Properties. In each project, depending on its type, select either Compile or Build, and set the Output path or Base output path to a folder to use for all projects in the solution.


1 Answers

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!

like image 177
Dmitry Pavlov Avatar answered Sep 20 '22 07:09

Dmitry Pavlov