How to copy files from One Project to another during build – C#

A couple of key points.

  • There are a some special variables you can use to aid you.
    $(SolutionDir) and $(ProjectDir) These will always resolve to where the project is sitting and remove you need to have to script out the entire path.
  • Xcopy is the tool you need to do the copy, but at the end of the command you need to add the /Y parameter to ensure you don’t exit with “code 2″
  • The Place you need to add this to make sure the copy takes place is the “Build Events” tab of one of you solutions project directories


xcopy “$(SolutionDir)ControlProject\*.ascx” “$(ProjectDir)UserControls\” /Y

IN the above example, all ascx files are copied from a directory under the Solution (in my case a project that contains a number of UserControls) to the local project’s UserControls directory.

The /Y specifying that we will overwrite any existing files/