VS2003: Copying a file to the output directory
I recently needed to create a VS 2003 project. The application is a simple console app that reads an xml file as input from the current directory. This is super simple to do on the command line but more obtuse from within VS.
Chris Sells offers some great info but it didn’t take me all the way there… At a high level what you need to do is set the post-build commandline to copy the file from the root of the project to correct bin dir. This sounds simple enough, but you have to use the right environment variables to get the path to workout correctly.
- Right click on the project->Properties
- Common Properties->Build Events
- Set Post-Build Event Command Line to
xcopy /y $(ProjectDir)sample.xml $(ProjectDir)$(OutDir)
- OK and build!
After building, in the Output window you should see status on this build step. For example
Performing Post-Build Event...
C:\NameTable\ConsoleApplication1\sample.xml
1 File(s) copied
Notice I use xcopy rather than copy as it seems to give better debugging diagnostics in the output window.
Oh, and I should note, this is WAY easier in VS2005 – simply right click on the file and select Properties and “Copy to output directory”. Here is to upgrades!
Hope this helps.