【问题标题】:How to get C# Cmdlet Parameter HelpMessage to show up in `Get-Help`如何让 C# Cmdlet Parameter HelpMessage 显示在“Get-Help”中
【发布时间】:2015-09-22 16:15:21
【问题描述】:

我已经启动了一个 PowerShell cmdlet,并希望提供参数的帮助消息。我已经尝试过使用ParameterAttribute.HelpMessage

[Cmdlet(VerbsCommon.Get, "Workspace", SupportsShouldProcess = true)]
public class GetWorkspace : PSCmdlet
{
    [Parameter(
        Mandatory = true,
        Position = 1,
        HelpMessage = "The path to the root directory of the workspace.")]
    public string Path { get; set; }

    protected override void ProcessRecord()
    {
        base.ProcessRecord();
    }
}

但是当我使用 PowerShell Get-Help 命令时,它没有显示参数的 HelpMessage:

get-help Get-Workspace -det

NAME
    Get-Workspace

SYNTAX
    Get-Workspace [-Path] <string> [-WhatIf] [-Confirm]  [<CommonParameters>]


PARAMETERS
    -Confirm

    -Path <string>

    -WhatIf

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).


ALIASES
    None


REMARKS
    None

在 PowerShell 脚本中编写 cmdlet 时,我可以使用以下语法为参数添加帮助消息:

<#
.Parameter Path
The local path to the root folder of the workspace.
#>

但是 C# cmdlet 中的等价物是什么?

【问题讨论】:

  • 查看 "XmlDoc2CmdletDoc" NuGet 包(以及一些 RedGate 博客帖子)。它可以让您获取标准 C# XML 注释并将其转换为令人惊叹的 Get-Help 文本

标签: c# powershell powershell-cmdlet


【解决方案1】:

你做的绝对正确!

您只需要检查-Full 视图或通过-Parameter 获取特定参数的帮助:

PS C:\> Get-Help Get-Workspace -Parameter Path

-Path <string>
    The path to the root directory of the workspace.

    Required?                    true
    Position?                    1
    Accept pipeline input?       false
    Parameter set name           (All)
    Aliases                      None
    Dynamic?                     false

【讨论】:

  • 谢谢。但我认为,我不必对 ps1 cmdlet 执行此操作。只需Get-Help Get-Workspace -det 即可看到参数帮助信息。这对于 C# cmdlet 是否无法实现?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多