How to know if error from dotnet build command with powershell How to know if error from dotnet build command with powershell powershell powershell

How to know if error from dotnet build command with powershell


You can merge the standard output and error streams with the > stream redirection operator, and then inspect the $LASTEXITCODE automatic variable to see if the call succeeded or not:

# Merge all streams into stdout$result = dotnet test *>&1# Evaluate success/failureif($LASTEXITCODE -eq 0){    # Success}else{    # Failed, you can reconstruct stderr strings with:    $ErrorString = $result -join [System.Environment]::NewLine}


For me it worked by just using exec in PS.

exec { dotnet build $projectFile -o $targetDir -c Release }