从 MSBuild 调用 PowerShell 会破坏长文本行
我有一个调用 PowerShell 脚本的 MSBuild 脚本。 PS 脚本的输出包含一些长行,其中一些(但不是全部)被分成多行,例如。
wait-untilOpCompleted : Cannot bind argument to parameter 'operationId' because
it is null.
我怎样才能阻止它这样做?我只想要一条长线,例如:
wait-untilOpCompleted : Cannot bind argument to parameter 'operationId' because it is null.
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
it 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
防止 PowerShell 根据控制台宽度换行的最简单方法是覆盖脚本顶部
Out-Default
的默认实现,如下所示: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:Keith的回答似乎较少侵扰性的。但是,如果您无法使其正常工作,您可以尝试的另一件事是手动设置主机的宽度。来自 上一个答案:
它只是在主机的 RawUI 输出缓冲区(不过,由于我们在多个环境中运行构建,并且我们不希望脚本仅仅因为它无法使输出更大一点而失败,因此代码相当具有防御性)。
如果您在始终设置 RawUI 的环境中运行(并且大多数都这样做),则代码可以大大简化:
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:
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: