I received the 'exited with code 4' error when the xcopy command tried to overwrite a readonly file. I managed to solve this problem by adding /R to the xcopy command. The /R indicates read only files should be overwritten
old command:
XCOPY /E /Y "$(ProjectDir)source file" "destination"
new command
XCOPY /E /Y /R "$(ProjectDir)source file" "destination"