简体   繁体   English

请参阅Visual Studio Code中的PowerShell Verbose输出

[英]See PowerShell Verbose output in Visual Studio Code

I am using Visual Studio Code 1.17.2 with the PowerShell extension (1.4.3). 我使用Visual Studio Code 1.17.2和PowerShell扩展(1.4.3)。 I have Write-Verbose statements in my code. 我的代码中有Write-Verbose语句。 When I run the PowerShell script, the Verbose output doesn't seem to go anywhere. 当我运行PowerShell脚本时, Verbose输出似乎Verbose可去。 How do I request that output be shown? 如何请求显示输出?

The simplest approach is to execute 最简单的方法是执行

$VerbosePreference = 'Continue'

in the integrated PowerShell console before invoking your script (and executing $VerbosePreference = 'SilentlyContinue' later to turn verbose output back off, if needed). 调用脚本之前在集成的PowerShell控制台中 (如果需要,稍后执行$VerbosePreference = 'SilentlyContinue'以关闭详细输出)。

From that point on: 从那时起:

  • running a script (starting it with ( F5 ) or without ( Ctrl+F5 ) the debugger) 运行脚本(用( F5 )或不用( Ctrl + F5 )调试器启动)

  • highlighting a section of code and running the selection ( F8 ) 突出显示一段代码并运行选择( F8

will make Write-Verbose calls produce output. 将使Write-Verbose调用产生输出。

If you want to preset $VerbosePreference = 'Continue' every time the integrated console starts, put that statement in the $PROFILE file : 如果要在每次集成控制台启动时预设 $VerbosePreference = 'Continue' ,请将该语句放在$PROFILE文件中

  • If your VS Code-specific $PROFILE file already exists, simply run psedit $PROFILE from the integrated console. 如果VS代码特定的 $PROFILE文件已存在,只需从集成控制台运行psedit $PROFILE即可。

  • If not, create the file first from the integrated console : New-Item -Type File $PROFILE 如果没有,请首先从集成控制台创建文件: New-Item -Type File $PROFILE

Verbose output by default it not shown, you need to declare [CmdletBinding()] in your function or script to enable the -Verbose parameter to be passed through in order have the option to display Verbose output. 默认情况下,详细信息未显示,您需要在函数或脚本中声明[CmdletBinding()]以启用-Verbose参数按顺序传递,以便显示详细输出。

You can 'cheat' though and pass -Verbose to Write-Verbose "Hello Verbose" -Verbose itself and that stream will appear in the console. 你可以“欺骗”并传递-VerboseWrite-Verbose "Hello Verbose" -Verbose本身,该流将出现在控制台中。

(Tested with your two matching versions for VSCode and Extension on Mac (PS6 Beta 8) and can see the verbose output). (测试了两个匹配版本的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM