August 30, 2011

Using Robocopy in Visual Studio Post Build Events

There are plenty of blog posts out there on this but I just tried following one and ran in to an issue I thought I’d write a quick post about.

I was trying to follow this blog post but the problem I ran in to is robocopy treats a trailing backslash as an escape character when it’s followed by a closing quote and my $(TargetDir) had spaces in it.  The solution I discovered has already been documented is to add a space after the variable.

So I ended up with the following code to copy the results of my build in to my Dropbox folder so my build gets synced from my notebook in Melbourne directly to the test PC setup in Los Angeles.

robocopy "$(TargetDir) " "C:\Users\Jonathan Benson\Documents\My Dropbox\Uppercut\UC3" /MIR /XF *.pdb *.xml *.vshost.* /NP /NJH
if errorlevel 4 goto BuildEventFailed
if errorlevel 0 goto end
:BuildEventFailed echo FILECOPY for $(ProjectName) FAILED
exit 1
:end echo FILECOPY for $(ProjectName) COMPLETED OK
exit 0

0 comments: