MSBuild in a Powershell Script - How do I know if the build succeeded? MSBuild in a Powershell Script - How do I know if the build succeeded? powershell powershell

MSBuild in a Powershell Script - How do I know if the build succeeded?


Check the value of $LastExitCode right after the call to MSBUILD. If it is 0, then MSBUILD succeeded, otherwise it failed.

BTW there is no need to use cmd /c. Just call MSBUILD.exe directly. We do that in PowerShell build scripts all the time.


To just check for success/failure, use the automatic variable $?.

PS> help about_Automatic_Variables    $?       Contains the execution status of the last operation. It contains    TRUE if the last operation succeeded and FALSE if it failed.

for example:

msbuildif (! $?) { throw "msbuild failed" }