簡體   English   中英

如何使用向導在Visual Studio 2017中添加項目模板

[英]how to add item template in visual studio 2017 using Wizard

說明:我正在開發一種解決方案,在該解決方案中,我將使用要添加的表單來調用模板項。

我想知道這是不是最好的解決方案,還是有另一種方法。

我的項目 我的項目

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

這種方法有效嗎? 還有其他方法嗎?

我創建了一個新方法來使用“ 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調用該項目

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM