I am invoking a PowerShell script from MSBuild. MSBuild is capable of capturing the return result, but believes that the project is built successfully.
The problem is that PowerShell exit code is not passed to the MSBuild command. Has anyone tried this before and were able to send 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 will be an error)
function CallFromMSBuild { Invoke-command {Powershell.exe C:\a.ps1} -computername $computers }
When the MSBuild project started, it should have caught the problem and the assembly should have failed (instead, it is believed that the assembly was successful)
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
powershell msbuild
Sanjeev Apr 28 '11 at 19:57 2011-04-28 19:57
source share