And*_*ott 4 c# powershell cmdlet
我已经启动了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();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我使用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
Run Code Online (Sandbox Code Playgroud)
在PowerShell脚本中编写cmdlet时,我可以使用以下语法为参数添加帮助消息:
<#
.Parameter Path
The local path to the root folder of the workspace.
#>
Run Code Online (Sandbox Code Playgroud)
但是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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
678 次 |
| 最近记录: |