Domanda

Supponiamo che tu stia scrivendo un po 'di href="http://msdn.microsoft.com/en-us/library/system.management.automation.pscmdlet%28v=vs.85%29.aspx" rel="NoreFerrer "> PSCMDLET in c #:

/// <summary>
/// Get a stack overflow exception.
/// </summary>
[Cmdlet(VerbsCommon.Join, "StackOverflow")]
[OutputType(typeof(OverflowException))]
public class JoinStackOverflow : PSCmdlet {
  protected override void ProcessRecord() {
    throw new OverflowException("stack");
  }
}
.

Se il modulo che definisce quanto sopra viene caricato in PowerShell, il comando help Join-StackOverflow restituirà quanto segue:

NAME
  Join-StackOverflow

SYNTAX
  Join-StackOverflow  [<CommonParameters>]

ALIASES
  None

REMARKS
  None
.

Come posso aggiungere una sinossi / riassunto per questo cmdlet, ad es.lo stesso del Get-Process:

NAME
  Get-Process

SYNOPSIS
  Gets the processes that are running on the local computer or a remote computer.

...
.

È stato utile?

Soluzione

Guida di cmdlet è normalmente nel file XML satellite.Supponendo che il cmdlet sia nel modulo mymodule.dll , il file della Guida è normalmente in mymodule \ en-us \ mymodule.dll-help.xml

Guida XML è così chiamato MAML-formato.Per evitare di poterlo comporre ogni volta che ho creato manualmente uno strumento (libreria di script) aiuta .Genera uno script di aiuto modello per un cmdlet che sembra un po 'simile per aiutare.Ecco un Esempio .Poi, dopo aver riempito gli spazi vuoti ( Esempio ), un altro comando aiuta è chiamato per convertire questo script in MAML XML.

P.S.Ci sono altri strumenti dell helper sul web.Ho provato un paio di loro e ho deciso di creare il mio.

Altri suggerimenti

Ecco la struttura di base del file MyModule.dll-help.xml, che può essere nella stessa directory del modulo DLL stesso o in una sottodirectory della cultura (come IT-US):

<!-- For a complete treatment of this format for PowerShell cmdlets, 
     see https://msdn.microsoft.com/en-us/library/bb525433.aspx -->
<command:command 
  xmlns:maml="http://schemas.microsoft.com/maml/2004/10"
  xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" 
  xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10">
  <command:details>
    <command:name>Verb-Noun</command:name>
    <command:verb></command:verb>
    <command:noun></command:noun>
    <maml:description><maml:para>Synopsis</maml:para></maml:description>
  </command:details>
  <maml:description><maml:para>Description</maml:para></maml:description>
  <command:syntax>
    <command:syntaxItem>
      <maml:name>Verb-Noun</maml:name>
      <command:parameter required="true" globbing="true" pipelineInput="true (ByValue)" position="1">
        <maml:name>ParameterName1</maml:name>
        <command:parameterValue required="true">string[]</command:parameterValue>
      </command:parameter>
      <command:parameter required="true" globbing="true" pipelineInput="true (ByPropertyName)">
        <maml:name>ParameterName2</maml:name>
        <command:parameterValue required="true">int32[]</command:parameterValue>
      </command:parameter>
      <!-- Additional parameter elements for each additional parameter. -->
    </command:syntaxItem>
    <!-- Additional syntaxItem elements for each additional parameter set. -->
  </command:syntax>
  <command:parameters>
    <command:parameter required="true" globbing="true" pipelineInput="true (ByValue)" position="1">
      <maml:name>ParameterName1</maml:name>
      <command:parameterValue required="true">string[]</command:parameterValue>
      <maml:description><maml:para>Parameter description</maml:para></maml:description>
      <dev:type>string[]</dev:type>
      <dev:defaultvalue>defaultvalue</dev:defaultvalue>
      <dev:possiblevalues>
        <dev:possiblevalue>
          <dev:value>value1</dev:value>
          <maml:description><maml:para>value description</maml:para></maml:description>
        </dev:possiblevalue>
        <dev:possiblevalue>
          <dev:value>value2</dev:value>
          <maml:description><maml:para>value description</maml:para></maml:description>
        </dev:possiblevalue>
      </dev:possiblevalues>
    </command:parameter>
    <command:parameter required="true" globbing="true" pipelineInput="true (ByPropertyName)">
      <maml:name>ParameterName2</maml:name>
      <maml:description><maml:para>Parameter description</maml:para></maml:description>
      <dev:type>int32[]</dev:type>
      <dev:defaultvalue>defaultvalue</dev:defaultvalue>
    </command:parameter>
    <!-- Additional parameter elements for each additional parameter. -->
  </command:parameters>
  <command:inputTypes>
    <command:inputType>
      <dev:type>
        <maml:name>System.String</maml:name>
        <maml:uri></maml:uri>
        <maml:description><maml:para></maml:para></maml:description>
      </dev:type>
      <maml:description><maml:para>You can pipe names …</maml:para></maml:description>
    </command:inputType>
    <!-- Additional inputType elements for each additional input type. -->
  </command:inputTypes>
  <command:returnValues>
    <command:returnValue>
      <dev:type>
        <maml:name>System.Object</maml:name>
        <maml:uri></maml:uri>
        <maml:description><maml:para></maml:para></maml:description>
      </dev:type>
      <maml:description><maml:para>When you …</maml:para></maml:description>
    </command:returnValue>
  </command:returnValues>
  <maml:alertSet>
    <maml:title>Note Title</maml:title>
    <maml:alert>
      <maml:para></maml:para>
    </maml:alert>
  </maml:alertSet>
  <command:examples>
    <command:example>
      <maml:title>----------  EXAMPLE 1  ----------</maml:title>
      <!-- The documentation (and SQLPS) suggests the PS C:\&gt; should go in the intro,
           but the dll-Help.xml files that come with PowerShell all seem to add it to the dev:code line. -->
      <maml:Introduction><maml:para>PS C:\&gt;</maml:para></maml:Introduction>
      <dev:code>Verb-Noun</dev:code>
      <dev:remarks>
        <maml:para> command description </maml:para>
        <!-- Two empty para elements signify the beginning of the output. -->
        <maml:para/>
        <maml:para/>
        <maml:para>output</maml:para>
      </dev:remarks>
    </command:example>
  </command:examples>
  <maml:relatedLinks>
    <maml:navigationLink><maml:linkText>Topic-name</maml:linkText><maml:uri></maml:uri></maml:navigationLink>
    <maml:navigationLink><maml:linkText>Topic-name</maml:linkText><maml:uri></maml:uri></maml:navigationLink>
  </maml:relatedLinks>
</command:command>
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top