Search code examples
c#visual-studiowizardvsixitemtemplate

how to add item template in visual studio 2017 using Wizard


Description: I'm developing a solution in which I'll call a template item with the form I want it to add.

And I wonder if this is the best solution to use or has another method.

my projectmy project

Code: calss1.vstemplate

 <VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
      <TemplateData>
        <DefaultName>class1.cs</DefaultName>
        <Name>Myproject class1</Name>
        <Description>Myproject Class</Description>
        <ProjectType>CSharp</ProjectType>
        <SortOrder>10</SortOrder>
        <Icon>Myprojectclass1.png</Icon>
      </TemplateData>
      <TemplateContent>
        <References>
          <Reference>
            <Assembly>System</Assembly>
          </Reference>
          <Reference>
            <Assembly>System.Linq</Assembly>
          </Reference>
          <Reference>
            <Assembly>System.Threading.Tasks</Assembly>
          </Reference>
        </References>
        <ProjectItem SubType="Code" TargetFileName="$fileinputname$.cs" ReplaceParameters="true">class1.cs</ProjectItem>
        <CustomParameters>  
            <CustomParameter Name="$username$" Value="$safeitemrootname$"/> 
            <CustomParameter Name="$rootnamespace$" Value="$safeitemrootname$"/>
            <CustomParameter Name="$registeredorganization$" Value="$safeitemrootname$"/>
        </CustomParameters>  
      </TemplateContent>
        //Call my Form
        <WizardExtension>
        <Assembly>MyProjectWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=f7a1fcb8d457e160</Assembly>
        <FullClassName>MyProjectWizard.WizardImplementation</FullClassName>
      </WizardExtension>
    </VSTemplate>

Is this method valid? Is there another method?


Solution

  • I created a new method to call the item template using the "WizardRunKind".

    This is the code I created:

        public void RunStarted(object automationObject,
        Dictionary<string, string> replacementsDictionary,
        WizardRunKind runKind, object[] customParams)
    {
        if (runKind.HasFlag(WizardRunKind.AsNewItem))
        {
            inputForm = new MyProjectModulo();
            inputForm.ShowDialog();
    
        }
    

    Note: Just call the item with the key.snk