我注意到,當MSBuild失敗時,$ LastExitCode變量的值始終爲0.我在Windows 7上使用MSBuild v4.0和PowerShell 2.0。這是我的MSBuild scritpt:
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Fail">
<Target Name="Fail">
<Error />
</Target>
</Project>
當我運行:
msbuild.exe MyProject.csproj
我可以在輸出看到的MSBuild失敗了,但是當我檢查$LastExitCode
,它具有0任何人都知道的值是什麼可能會繼續?
我試過設置$(ErrorActionPreference)
到Stop
,但沒有奏效。我重新打開了一個新的PowerShell窗口,但這也不起作用。
我試過你的情況,並且$ LastExitCode是1. – 2011-04-09 09:36:26
在檢查變量之前是否運行了其他本地命令? – Joey 2011-04-09 10:22:43