如何使用向导在Visual Studio 2017中添加项目模板

时间:2018-11-13 11:42:36

标签: c# visual-studio wizard vsix itemtemplate

说明: 我正在开发一种解决方案,在该解决方案中,我将使用要添加的表单形式来调用模板项。

我想知道这是最好的解决方案还是其他方法。

my project我的项目

代码: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>

此方法有效吗? 还有另一种方法吗?

1 个答案:

答案 0 :(得分:0)

我创建了一个新方法来使用“ WizardRunKind”调用项目模板。

这是我创建的代码:

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

    }

注意:只需使用key.snk调用该项目

相关问题