问题
I have the following exec task, performing checkin of assemblyinfo.cs files. I'm trying to return the exit code, but for some reason it is always empty.
<!--Checkin if all succeeded-->
<Exec Condition=" '$(LocalCompilationSuccess)' != 'Failed' and '$(LocalTestSuccess)' != 'Failed' " ContinueOnError="True"
Command='"$(TfCommand)" checkin /recursive /comment:"$(NoCICheckInComment) $(BuildDefinitionName): build succeeded, checkin changes." /override:"TeamBuild $(BuildDefinitionName)" $/SomeProject/Trnk' WorkingDirectory="$(SolutionRoot)" >
<Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
</Exec>
I've tried to read the exit code in 2 ways:
'%(ErrorCode.Identity)'
'$(ErrorCode)'
Both are empty. Any suggestions?
回答1:
In general it works as you have shown.
For reference, here is a more "selfcontained" example:
<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>
A couple of things you may want to consider however:
Make sure your
Exec
even executes, that isCondition
evaluates toTrue
.Output the
ErrorCode
property using theMessage
-Task, to see if it is actually set (to the value you expect). However, make sure MSBuild will show the output, by either usingImportance='high'
or by runningmsbuild.exe /v:d
to enable detailed messages.
来源:https://stackoverflow.com/questions/11096148/msbuild-exec-task-exit-code-empty