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

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!


Please try select the file in Solution Explorer. Then you should be able to see its properties in Properties window (press F4 if it is not visible). You will find there two properties:

  • "Build Action" and
  • "Copy to Output Directory"

Set "Build Action" to "Content", and then - select an appropriate value for "Copy to Output Directory" setting.

File properties window with "Build Action" and "Copy to Output Directory" settings

File properties window with "Build Action" and "Copy to Output Directory" settings

If the way above doesn't work for you, please read this post "Copy to output directory issue with .inf file". And have a look at this one then "Visual Studio: default build action for non-default file-types"

Hope that helps


While I was searching the file’s Property Page for a build-action field, I had a thought: set the custom build step to copy the file (manually). This turned out to be easier than I thought. I had figured it would require using cmd or other external executable (xcopy, robocopy, etc.), but that is not necessary.

I set the Custom Build Step as follows:

Command Line : copy $(InputFileName) $(OutDir)
Description  : Copying foobar...
Outputs      : $(InputFileName)

Setting the outputs field (correctly) was critical in order to prevent VS from always thinking the project is out of date and requiring to be rebuilt (I’m not certain if it needs to be prefixed with $(OutDir)\).

It is reflected in the Output window as such:

Copying foobar...
        1 file(s) copied.
Compiling resources...
Linking...