Post Build exited with code 1

I have added this for future visitors since this is quite an active question.

ROBOCOPY exits with "success codes" which are under 8. See: http://support.microsoft.com/kb/954404

This means that:

robocopy exit code 0 = no files copied
robocopy exit code 1 = files copied
When the result is 1, this becomes an error exit code in visual studio.

So i solved this easily by adding this to the bottom of the batch file

exit 0

Suggest that handle ROBOCOPY errors in this fashion

rem each robocopy statement and then underneath have the error check.
if %ERRORLEVEL% GEQ 8 goto failed

rem end of batch file
GOTO success

:failed
rem do not pause as it will pause msbuild.
exit 1

:success
exit 0    

Confusion will set in when no files are copied = no error in VS. Then when there are changes, files do get copied, VS errors but everything the developer wanted was done.

Additional Tip: Do not use a pause in the script as this would become an indefinite pause in the VS build. while developing the script, use something like timeout 10. You will notice this and comment it out rather than have a hanging build.


She had a space in one of the folder names in her path, and no quotes around it.


The one with the "Pings" helped me... but may be explained a little better...

For me the solution was to change:

copy $(TargetDir)$(TargetName).* $(SolutionDir)bin

to this:

copy "$(TargetDir)$(TargetName).*" "$(SolutionDir)bin"

Hope it works for you. :-)