我已经启动了一个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中等效的是什么?
你做得完全正确!
您只需要检查-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