zampotex
zampotex

Reputation: 327

msbuild fails with successful robocopy exit code

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" />

Upvotes: 6

Views: 4938

Answers (2)

Nikerboker
Nikerboker

Reputation: 833

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; 7" Message="Robocopy failed"/>

Upvotes: 9

Anton Gogolev
Anton Gogolev

Reputation: 115741

Try this workaround:

(robocopy  $(SourceDir) $(DestinationDir) /mir /mt /xd $(ExcludeDir)) ^& IF %ERRORLEVEL% LEQ 1 exit 0

Upvotes: 5

Related Questions