5

My msbuild script fails even if copying files is successful. If robocopy command exitcode < 8, it means that files copied. So how can I say to msbuild script IgnoreExitCode if exit code < 8? I set IgnoreExitCode to true, but what if it's real error?

<Exec Command="robocopy  $(SourceDir) $(DestinationDir) /mir /mt /xd $(ExcludeDir)" IgnoreExitCode="true" />
zampotex
  • 317
  • 4
  • 9

2 Answers2

7

Use ExitCode output parameter of Exec task and ContinueOnError parameter instead of IgnoreExitCode:

<Exec ContinueOnError="True" Command="robocopy  $(SourceDir) $(DestinationDir) /mir /mt /xd $(ExcludeDir)">
   <Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
</Exec>
<Error Condition="$(ErrorCode) &gt; 8" Message="Robocopy failed"/>
Nikerboker
  • 764
  • 7
  • 14
4

Try this workaround:

(robocopy  $(SourceDir) $(DestinationDir) /mir /mt /xd $(ExcludeDir)) ^& IF %ERRORLEVEL% LEQ 1 exit 0
Community
  • 1
  • 1
Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288