Calling PowerShell from MSBuild breaks long lines of text
I have an MSBuild script that calls a PowerShell script. The output of the PS script contains some long lines and some of those (but not all) are broken up into multiple lines, eg.
wait-untilOpCompleted : Cannot bind argument to parameter 'operationId' because
i开发者_开发问答t is null.
How do I stop it from doing that? I just want one long line, eg.:
wait-untilOpCompleted : Cannot bind argument to parameter 'operationId' because it is null.
The easiest way to prevent PowerShell from breaking lines based on the console's width is to override the default implementation of Out-Default
at the top of your script like so:
filter Out-Default {
$input | Out-String -Width 500 -Stream |
Microsoft.PowerShell.Utility\out-default
}
Keith's answer seems less intrusive. However, if you have not been able to get it to work, another thing you might try is manually setting the width of the host. From a previous answer:
# Update output buffer size to prevent clipping in Visual Studio output window.
if( $Host -and $Host.UI -and $Host.UI.RawUI ) {
$rawUI = $Host.UI.RawUI
$oldSize = $rawUI.BufferSize
$typeName = $oldSize.GetType( ).FullName
$newSize = New-Object $typeName (500, $oldSize.Height)
$rawUI.BufferSize = $newSize
}
It simply sets a new width of 500 characters on the host's RawUI output buffer (though, since we run our build in several environments, and we did not want the script to fail just because it could not make the output a bit larger, the code is rather defensive).
If you run in an environment that always sets RawUI (and most do), the code can be greatly simplified:
$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (500, 25)
精彩评论