我正在從MSBuild調用PowerShell腳本。 MSBuild能夠捕獲返回的輸出,但認爲該項目已成功構建。PowerShell退出代碼 - 從MSBuild調用
問題是來自PowerShell的退出代碼沒有傳遞給MSBuild中的命令。有人曾經嘗試過,並能夠拋出退出代碼到MSBuild?
testmsbuild.proj
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="DesktopBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ScriptLocation>c:\scripts\test.ps1</ScriptLocation>
</PropertyGroup>
<Target Name="AfterDropBuild" >
<Exec Command="powershell.exe -NoProfile -Noninteractive -command "& { $(ScriptLocation)%3Bexit $LASTEXITCODE }" " >
<Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
</Exec>
</Target>
</Project>
test.ps1(當然這是要出錯誤)
function CallFromMSBuild {
Invoke-command {Powershell.exe C:\a.ps1} -computername $computers
}
當MSBuild項目被觸發時,它應該抓住這個問題,並在構建宜已經失敗(認爲建立成功)
當我從MSBuild打電話
C:\Scripts>msbuild testmsbuild.proj /t:AfterDropBuild
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.225]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 4/28/2011 2:46:29 PM.
Project "C:\scripts\testmsbuild.proj" on node 1 (AfterDropBuild target(s)).
AfterDropBuild:
powershell.exe -NoProfile -Noninteractive -command "& { c:\scripts\test.ps1;e
xit $LASTEXITCODE }"
Invoke-Command : Cannot validate argument on parameter 'ComputerName'. The argu
ment is null or empty. Supply an argument that is not null or empty and then tr
y the command again.
At C:\install\test.ps1:3 char:58
+ Invoke-command {Powershell.exe C:\a.ps1} -computername <<<< $computers
+ CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBind
ingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
Shell.Commands.InvokeCommandCommand
Done Building Project "C:\scripts\testmsbuild.proj" (AfterDropBuild target(s)).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.04
相關:http://stackoverflow.com/questions/78069/any-good-powershell-msbuild-tasks – 2012-12-13 21:46:14