Correct syntax to copy and overwrite a file in a post build event
post-build-event, robocopy, visual-studio-2010, xcopy
Solution
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`
Problem
What is the best way to copy and always overwrite a file to the target directory in a postbuild event in VS2010 running on windows 7. At the moment I am using ``` robocopy $(SolutionDir) $(TargetDir) "Morning Report Template.xlsm" ``` I have also tried using Xcopy (with /Y) and even just plain copy. But I have not made it work properly yet. Either I get build errors like "The command "robocopy C:\Working\Projects\SAFEXQueryForm\ C:\Working\Projects\SAFEXQueryForm\SAFEXQueryForm\bin\Release\ "Morning Report Template.xlsm"" exited with code 1." Or else it just doesn't copy. I need it to copy and overwrite everytime, without build errors and I would also prefer to change the file name which I know Robocopy can't do. What am I doing wrong? And what is the best way to do this?