Capturing MSBuild.exe output in a PowerShell script
build-script, msbuild, powershell
Solution
If you want to pipe output from msbuild to a logging or processing cmdlet, you should not be starting it with `Start-Process`, just execute it normally.
PS> msbuild.exe $flag1 $flag2 $thingToBuild | Write-Buildlog
You might need to also redirect stderr to capture more of the output. In that case you would need to add `2>&1`
PS> msbuild.exe $flag1 $flag2 $thingToBuild 2>&1 | Write-Buildlog
`Start-Process` will start your process outside of any powershell environment or hosting, so obtaining output and sending to cmdlets becomes much more difficult. If you want to process executable output in powershell, then it's best to simply stay within a powershell environment the whole time.
Problem
I'm creating some new build scripts for a project using PowerShell, and would like to capture the output of MSBuild when I call it and save that to a text file. I've tried a couple different methods of doing so with no luck so far--here's what I last tried (Write-Buildlog just handles writing off the output to the log): Start-Process $msBuildExecutable $buildArgs -Wait | Write-Buildlog No output at all is captured, though MSBuild runs fine. Any tips would be greatly appreciated as I've done a bit of searching and have found nothing useful so far, which is surprising :) Thanks!