msbuild 失败并显示成功的 robocopy 退出代码

问题描述 投票:0回答:2

即使复制文件成功,我的 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" />
msbuild robocopy
2个回答
8
投票

使用Exec任务的ExitCode输出参数和ContinueOnError参数而不是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"/>

4
投票

尝试这个解决方法

(robocopy  $(SourceDir) $(DestinationDir) /mir /mt /xd $(ExcludeDir)) ^& IF %ERRORLEVEL% LEQ 1 exit 0
© www.soinside.com 2019 - 2024. All rights reserved.