Every now and then when I build my solution here (with 7 projects in it) I get the dreaded \'Command copy exited with code 4\' error, in Visual Studio 2010 Premium ed.
While /C
may ignore errors, it might not be the real solution as there could be files that MUST be copied in order for the build to be successful.
The most common issue is the missing quotes around the pre-defined command tags (such as $TargetDir
). When one creates various branches and paths in code or TFS, there is a very high chance for this to occur.
Sometimes if the file is read only, it will cause issues too. Add the /R
option to allow read only files to be copied over. You can find list of available options at:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true
Another possible issue is that the underlying folder cannot be accessed. If so, trying performing "start xcopy"
instead of "xcopy"
. This will open another command window but with admin priveleges.
I had the same problem. However, nothing worked for me. I solved the issue by adding
exit 0
to my code. The problem was that while I was doing copying of the files, sometimes the last file could not be found, and the bat returned a non-zero value.
Hope this helps someone!
I don't see anything in here to suggest that this is a web-app but I have experienced this issue myself - I've got two xcopy commands on a post-build event and only one of them was failing. Something had a lock on the file, and it wasn't Visual Studio (as I tried restarting it.)
The only other thing that would have used the dll I built was IIS. And lo and behold,
A simple iisreset
did the trick for me.
I crossed the same error, but it is not due to the file is locked, but the file is missing.
The reason why VS tried to copy an not existing file, is because of the Post-build event command.
After I cleared that, problem solved.
UPDATE:
As @rhughes commented:
The real issue is how to get the command here to work, rather than to remove it.
and he is absolutely right.
To expand on rhughes answer,
The robocopy works beautifully, just incase you need to include sub directories you can use /e
to include subs and copy empty directories or /s
to include subs excluding empty directories.
Also robocopy will report back a few things like if new files were copied, this will cause VS to complain since anything above 0 is a failure and robocopy will return 1 if new files have been found. Its worth to mention that robocopy first compares the Source/Dest and only copies the updated/new files.
To get around this use:
(robocopy "$(SolutionDir)Solution Items\References\*.dll" "$(TargetDir)") ^& IF %ERRORLEVEL% LEQ 4 exit /B 0
I got this error because the user account that TFS Build Service was running under did not have permissions to write to the destination folder. Right-click on the folder-->Properties-->Security
.