I'm invoking a PowerShell script from MSBuild. MSBuild is able to capture the output returned, but thinks the project is built successfully.
The problem is that the exit code from PowerShell is not passed to the command in MSBuild. Has someone tried this before and been able to throw an exit code to 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 (of course this is going to error out)
function CallFromMSBuild {
Invoke-command {Powershell.exe C:\a.ps1} -computername $computers
}
When MSBuild project is triggered, it should have caught the issue and the build should have failed (considers build succeeded instead)
When I call from 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