Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 使用Visual Studio代码查看my函数的docstring_Powershell_Visual Studio Code - Fatal编程技术网

Powershell 使用Visual Studio代码查看my函数的docstring

Powershell 使用Visual Studio代码查看my函数的docstring,powershell,visual-studio-code,Powershell,Visual Studio Code,我是Visual Studio代码的新手,我开始使用它来开发PowerShell脚本 我看到,当我将光标放在函数名上时,我得到了函数参数的概览,但当我使用自己的自定义函数进行操作时,它却没有这样做 如何声明可以通过Visual Studio代码在概述中显示的PowerShell函数的文档 我试着这样做: <# .Description Get-Function displays the name and syntax of all functions in the session. #&g

我是Visual Studio代码的新手,我开始使用它来开发PowerShell脚本

我看到,当我将光标放在函数名上时,我得到了函数参数的概览,但当我使用自己的自定义函数进行操作时,它却没有这样做

如何声明可以通过Visual Studio代码在概述中显示的PowerShell函数的文档

我试着这样做:

<#
.Description
Get-Function displays the name and syntax of all functions in the session.
#>
function test([string]$print){}


<# Setup the working directories if they do not exist #>
If(!(Test-Path $WORKING_DIRECTORY)) {test}
但这似乎不起作用

非常感谢

在描述中添加.参数对我很有用。还请注意,我相信您必须保存并运行脚本一次,以便它显示

<#
.Description
Get-Function displays the name and syntax of all functions in the session.
.PARAMETER  
#>

function test([string]$print){Write-Host $print}

If(Test-Path $env:userprofile) {test -print "Test123"}
在描述中添加.PARAMETER对我很有用。还请注意,我相信您必须保存并运行脚本一次,以便它显示

<#
.Description
Get-Function displays the name and syntax of all functions in the session.
.PARAMETER  
#>

function test([string]$print){Write-Host $print}

If(Test-Path $env:userprofile) {test -print "Test123"}

我之前的回答是不正确的,尽管阅读上一篇文章仍然是编写cmdlet文档的好主意

为了让vscode能够了解您的函数定义,需要在其内部Powershell主机中定义函数。如果可以打开Powershell集成终端,则可以像运行脚本一样运行源代码。myScript.ps1读取中的函数定义。在运行任何要执行的代码之前,您可能需要将运行时代码放入if块检查脚本是否源于点,但将函数定义保留在此条件之外

脚本在Powershell集成终端中点源化后,您将获得所需的用法工具提示弹出窗口。要使其自动化,请按vsvode终端的解析,从$profile中点源脚本


这并不是特别理想,我希望找到一个更精简的解决方案,因为我使用的每个脚本都要点源代码是很麻烦的。

我以前的回答是不正确的,尽管阅读上一篇文章对于一般记录cmdlet来说仍然是一个好主意

为了让vscode能够了解您的函数定义,需要在其内部Powershell主机中定义函数。如果可以打开Powershell集成终端,则可以像运行脚本一样运行源代码。myScript.ps1读取中的函数定义。在运行任何要执行的代码之前,您可能需要将运行时代码放入if块检查脚本是否源于点,但将函数定义保留在此条件之外

脚本在Powershell集成终端中点源化后,您将获得所需的用法工具提示弹出窗口。要使其自动化,请按vsvode终端的解析,从$profile中点源脚本

这并不是特别理想,我希望找到一个更精简的解决方案,因为我使用的每个脚本都要点源代码是很麻烦的