即使复制文件成功,我的 msbuild 脚本也会失败。如果 robocopy 命令退出代码 < 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" />
使用Exec任务的ExitCode输出参数和ContinueOnError参数而不是IgnoreExitCode:
<Exec ContinueOnError="True" Command="robocopy $(SourceDir) $(DestinationDir) /mir /mt /xd $(ExcludeDir)">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
</Exec>
<Error Condition="$(ErrorCode) > 7" Message="Robocopy failed"/>
尝试这个解决方法:
(robocopy $(SourceDir) $(DestinationDir) /mir /mt /xd $(ExcludeDir)) ^& IF %ERRORLEVEL% LEQ 1 exit 0