MSBuild执行任务,退出代码为空。

8

我有以下exec任务,执行assemblyinfo.cs文件的checkin操作。我尝试返回退出代码,但出于某种原因它总是空白。

<!--Checkin if all succeeded-->
<Exec Condition=" '$(LocalCompilationSuccess)' != 'Failed' and '$(LocalTestSuccess)' != 'Failed' " ContinueOnError="True"
              Command='&quot;$(TfCommand)&quot; checkin /recursive /comment:"$(NoCICheckInComment) $(BuildDefinitionName): build succeeded, checkin changes." /override:"TeamBuild $(BuildDefinitionName)" $/SomeProject/Trnk' WorkingDirectory="$(SolutionRoot)"  >
  <Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
</Exec>

我尝试以两种方式读取退出代码:

'%(ErrorCode.Identity)'
'$(ErrorCode)'

两者都是空的。有什么建议吗?

奇怪,尝试使用<Message Text="The exit code is $(ErrorCode)"/> - sll
1个回答

20

总的来说,它的工作方式就像您所展示的那样。

供参考,这里有一个更具“自包含性”的例子:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <Target Name="help">
    <Exec ContinueOnError="True" Command='cmd.exe /c dir'>
       <Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
    </Exec>
    <Message Importance="high" Text="$(ErrorCode)"/>
  </Target>
</Project>

然而,以下几点需要考虑:

  • 确保你的Exec命令实际执行了,即Condition评估为True

  • 使用Message任务输出ErrorCode属性,查看其是否已设置(以您预期的值)。但是,请确保MSBuild将显示输出,要么使用Importance='high',要么运行msbuild.exe /v:d以启用详细消息。


由于条件阻止方法被调用而引起的问题。谢谢。 - jaspernygaard
2
在mono/xbuild下,我还必须在<Exec>任务中指定IgnoreExitCode="true"才能填充该属性。 - weirdan
3
此外,由于 https://github.com/nunit/nunit-console/issues/242,我建议设置 IgnoreStandardErrorWarningFormat="true"。否则 ExitCode 可能是 -1,而不是启动进程的实际退出代码。 - matthid

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接