如何在“Get-Help”中显示C#Cmdlet参数HelpMessage

我已经启动了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]  [-WhatIf] [-Confirm] [] PARAMETERS -Confirm -Path  -WhatIf  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时,我可以使用以下语法为参数添加帮助消息:

  

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

你这样做是绝对正确的!

您只需要检查-Full视图或使用-Parameter获取特定参数的-Parameter

 PS C:\> Get-Help Get-Workspace -Parameter Path -Path  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