PowerShell exit code - Calling from MSBuild

后端 未结 3 1314
渐次进展
渐次进展 2020-12-30 07:49

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 th

3条回答
  •  梦毁少年i
    2020-12-30 08:03

    Add exit $lastexitcode to test.ps1

    After comment:

    Try this in test.ps1:

    trap {Write-Host -foreground red $_.Exception.Message; exit 1; continue} Invoke-command   {Powershell.exe C:\a.ps1} -computername $computers
    

    Basically, I don't think MSBuild is at fault here.

    I tried your wrong Invoke-Command and the $lastexitcode was set to 0 even though the Invoke-Command had failed! You can test whether this works or not from cmd itself by doing echo %errorlevel% and see you get 1.

提交回复
热议问题