![](/img/trans.png)
[英]Powershell / Visual Studio Code: Update version of Powershell in Visual Studio Code
[英]See PowerShell Verbose output in Visual Studio Code
我使用Visual Studio Code 1.17.2和PowerShell扩展(1.4.3)。 我的代码中有Write-Verbose
语句。 当我运行PowerShell脚本时, Verbose
输出似乎Verbose
可去。 如何请求显示输出?
最简单的方法是执行
$VerbosePreference = 'Continue'
在调用脚本之前在集成的PowerShell控制台中 (如果需要,稍后执行$VerbosePreference = 'SilentlyContinue'
以关闭详细输出)。
从那时起:
运行脚本(用( F5 )或不用( Ctrl + F5 )调试器启动)
突出显示一段代码并运行选择( F8 )
将使Write-Verbose
调用产生输出。
如果要在每次集成控制台启动时预设 $VerbosePreference = 'Continue'
,请将该语句放在$PROFILE
文件中 :
如果VS代码特定的 $PROFILE
文件已存在,只需从集成控制台运行psedit $PROFILE
即可。
如果没有,请首先从集成控制台创建文件: New-Item -Type File $PROFILE
默认情况下,详细信息未显示,您需要在函数或脚本中声明[CmdletBinding()]
以启用-Verbose
参数按顺序传递,以便显示详细输出。
你可以“欺骗”并传递-Verbose
到Write-Verbose "Hello Verbose" -Verbose
本身,该流将出现在控制台中。
(测试了两个匹配版本的VSCode和Mac版扩展(PS6 Beta 8),可以看到详细的输出)。
function Test-Verbose {
# This enables the function to have '-Verbose'.
[CmdletBinding()]
param()
Write-Output "Hello output!"
# Will only be displayed if 'Test-Verbose' is passed '-Verbose'.
Write-Verbose "Hello verbose"
}
Test-Verbose -Verbose
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.