[c#] Copy file(s) from one project to another using post build event...VS2010

I have a solution with 3 projects in it. I need to copy a view from one project to another. I'm able to copy the created DLL via post build events like so:

enter image description here

So i want to copy the file in project one '/Views/ModuleHome/Index.cshtml' to a folder in project 2. How do I copy file(s) to my desired project via post-build event? Thanks

This question is related to c# visual-studio-2010

The answer is


If you want to take into consideration the platform (x64, x86 etc) and the configuration (Debug or Release) it would be something like this:

xcopy "$(SolutionDir)\$(Platform)\$(Configuration)\$(TargetName).dll" "$(SolutionDir)TestDirectory\bin\$(Platform)\$(Configuration)\" /F /Y 

I use it like this.

xcopy "$(TargetDir)$(TargetName).dll" "$(SolutionDir)Lib\TIRM\x86\" /F /Y 
xcopy "$(TargetDir)$(TargetName).lib" "$(SolutionDir)Lib\TIRM\x86\" /F /Y 


/F : Copy source is File   
/Y : Overwrite and don't ask me

Note the use of this. $(TargetDir) has already '\' "D:\MyProject\bin\" = $(TargetDir)

You can find macro in Command editor

enter image description here


This command works like a charm for me:

for /r "$(SolutionDir)libraries" %%f in (*.dll, *.exe) do @xcopy "%%f" "$(TargetDir)"

It recursively copies every dll and exe file from MySolutionPath\libraries into the bin\debug or bin\release.

You can find more info in here


xcopy "$(TargetDir)*$(TargetExt)" "$(SolutionDir)\Scripts\MigrationScripts\Library\" /F /R /Y /I

/F – Displays full source & target file names

/R – This will overwrite read-only files

/Y – Suppresses prompting to overwrite an existing file(s)

/I – Assumes that destination is directory (but must ends with )

A little trick – in target you must end with character \ to tell xcopy that target is directory and not file!


Like the previous replies, I'm also suggesting xcopy. However, I would like to add to Hallgeir Engen's answer with the /exclude parameter. There seems to be a bug with the parameter preventing it from working with path names that are long or that contain spaces, as quotes will not work. The path names need to be in the "DOS"-format with "Documents" translating to "DOCUME~1" (according to this source).

So, if you want to use the \exclude parameter, there is a workaround here:

cd $(SolutionDir)
xcopy "source-relative-to-path-above" "destination-relative-to-path-above
/exclude:exclude-file-relative-path

Note that the source and destination paths can (and should, if they contain spaces) be within quotes, but not the path to the exclude file.


xcopy "your-source-path" "your-destination-path" /D /y /s /r /exclude:path-to-txt- file\ExcludedFilesList.txt

Notice the quotes in source path and destination path, but not in path to exludelist txt file.

Content of ExcludedFilesList.txt is the following: .cs\

I'm using this command to copy file from one project in my solution, to another and excluding .cs files.

/D Copy only files that are modified in sourcepath
/y Suppresses prompting to confirm you want to overwrite an existing destination file.
/s Copies directories and subdirectories except empty ones.
/r Overwrites read-only files.

Call Batch file which will run Xcopy for required files source to destination

call "$(SolutionDir)scripts\copyifnewer.bat"