Copy File(S) from One Project to Another Using Post Build Event...Vs2010

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

xcopy "$(ProjectDir)Views\Home\Index.cshtml" "$(SolutionDir)MEFMVCPOC\Views\Home"

and if you want to copy entire folders:

xcopy /E /Y "$(ProjectDir)Views" "$(SolutionDir)MEFMVCPOC\Views"

Update: here's the working version

xcopy "$(ProjectDir)Views\ModuleAHome\Index.cshtml" "$(SolutionDir)MEFMVCPOC\Views\ModuleAHome\" /Y /I

Here are some commonly used switches with xcopy:

  • /I - treat as a directory if copying multiple files.
  • /Q - Do not display the files being copied.
  • /S - Copy subdirectories unless empty.
  • /E - Copy empty subdirectories.
  • /Y - Do not prompt for overwrite of existing files.
  • /R - Overwrite read-only files.

Correct syntax to copy and overwrite a file in a post build event

EDIT 2015/11/23

This answer provides a better method: https://stackoverflow.com/a/4596552/1011724. You can add the file to the project and then change the "Copy to Output Directory" property of the file.


Original answer

I still don't know what was wrong with my original syntax or how to convince VS that Robocopy's success exit code is 1 but this is what I have now and it seems to work, the only difference being that I changes the directory structure but that shouldn't matter(I'm afraid I don't know if I made other changes in the interim, this was quite a while ago)

xcopy "$(SolutionDir)\Additional Files\Morning Report Template.xlsm" "$(TargetDir)" /Y

and also I have the Run post build event drop down set to On successful build

Copy dll modified in post-build to obj folder

Can this be done automatically, or is it only possibly via another post-build-command to copy the dll by hand?

The answer is yes, you can add a xcopy command after Modifying the dll in post-build-command:

echo Execute Modifying dll Event.
xcopy.exe "$(ProjectDir)TheModifyiedFolder\Modifying.dll" "$(ProjectDir)obj" /y /s

Adding pre-build commands to copy files to a project in VS 2017

Projects have a Pre-build event that can be used for doing what you are looking to do.

You can find this in the Project Properties in the Build Events section.
Try the command as per:

c:\windows\system32\xcopy D:\source\*.* "$(TargetDir)" /s /e

For a list of the Build Parameters see MSDN: https://msdn.microsoft.com/en-us/library/42x5kfw4.aspx

The quotes around the $(TargetDir) are important if you have a space in any of your folder/file names

Copy bin files on to Physical file location on Post Build event in VS2010

You want to add something like:

xcopy /Q /Y "$(TargetPath)" "C:\path\to\somewhere\"

to you post-build event on the Build Events tab in the project properties page. The /Y will stop it from prompting you to confirm an overwrite.

If you also need to copy the .pdb file, you will need something like this:

xcopy /Q /Y "$(TargetDir)$(TargetName).*" "C:\path\to\somewhere\"

You can see more substitution tokens (the $XXX values) by clicking the Edit Post-build... button in the properties tab and then expanding the Macros>> button.



Related Topics



Leave a reply



Submit