2009-06-29 42 views
14

我想創建一個多項目模板。我希望子項目名稱包含解決方案名稱。我已經嘗試了以下方法,但是出於某種原因,$ safeprojectName $在根模板中不起作用。它試圖在名稱中使用$ safeprojectName $創建文件夾,而不是實際的項目名稱。爲visual studio創建多個項目模板時,是否有一種方法可以使用根模板文件中的參數?

<VSTemplate Version="2.0.0" Type="ProjectGroup" 
    xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"> 
    <TemplateData> 
    <Name>Default Solution</Name> 
    <Description>An example of a multi-project template</Description> 
    <Icon>Icon.ico</Icon> 
    <ProjectType>CSharp</ProjectType> 
    </TemplateData> 
    <TemplateContent> 
    <ProjectCollection> 
     <SolutionFolder Name="$safeprojectName$.Web"> 
     <ProjectTemplateLink ProjectName="$safeprojectName$.Web"> 
      Src\Web\MyTemplate.vstemplate 
     </ProjectTemplateLink> 
     </SolutionFolder> 
    </ProjectCollection> 
    </TemplateContent> 
</VSTemplate> 

我已經做了大量的閱讀,並且已經創建了一個使用創建參數$ solutionName $的IWizard接口的程序集。然後我使用了以下模板。

<VSTemplate Version="2.0.0" Type="ProjectGroup" 
    xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"> 
    <TemplateData> 
    <Name>Default Solution</Name> 
    <Description>An example of a multi-project template</Description> 
    <Icon>Icon.ico</Icon> 
    <ProjectType>CSharp</ProjectType> 
    </TemplateData> 
    <TemplateContent> 
    <ProjectCollection> 
     <SolutionFolder Name="$solutionName$.Web"> 
     <ProjectTemplateLink ProjectName="$solutionName$.Web"> 
      Src\Web\MyTemplate.vstemplate 
     </ProjectTemplateLink> 
     </SolutionFolder> 
    </ProjectCollection> 
    </TemplateContent> 
    <WizardExtension> 
    <Assembly>DefaultSoloutionWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=f753ddb61a28cb36, processorArchitecture=MSIL</Assembly> 
    <FullClassName>DefaultSoloutionWizard.WizardImplementation</FullClassName> 
    </WizardExtension> 
</VSTemplate> 

然而,這也失敗,出現同樣的問題。我正在努力去做不可能的事情?任何對此的幫助將是最受歡迎的。

回答

2

你可能想看看進入Guidance Automation Toolkit。這裏有相當多的消化,但它可以做的一部分是在多項目模板上放置一個基於嚮導的UI。

如果您想查看該示例,請查看Service Factory,它可以部分基於嚮導創建整個解決方案結構。

1

是的,你需要使用一個靜態字典在根模板的嚮導,這將是由嚮導執行的子模板中使用:在根模板

IWizard實施

public void RunStarted(object automationObject, 
     Dictionary<string, string> replacementsDictionary, 
     WizardRunKind runKind, object[] customParams) 
    { 
     try 
     { 
      // Display a form to the user. The form collects 
      // input for the custom message. 
      inputForm = new UserInputForm(); 
      inputForm.ShowDialog(); 

      customMessage = inputForm.get_CustomMessage(); 

      // Add custom parameters. 
      replacementsDictionary.Add("$custommessage$", 
       customMessage); 
      globalDictionary = new Dictionary<string, string>(); 
      globalDictionary.Add("$custommessage$", 
       customMessage); 

     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.ToString()); 
     } 
    } 

    public static Dictionary<string, string> globalDictionary; 

你可以得到在此實現的完整示例:Multi-Project Templates with Wizard: Visual Studio 2010 Sample

+0

運行在調試該項目BSOD'd我的VS 2010 SP 1 – 2011-03-11 04:41:07

4

從Visual Studio 2013 Update 2開始,現在可以在根.vstemplate文件中的ProjectTemplateLink元素上使用CopyParameters屬性。在根模板中定義的任何參數都將在帶有「ext_」前綴的鏈接模板中可用。

例如,如果根模板定義參數,$ $符,則該參數$ $ ext_Foo將在具有相同值的鏈接項目可用。

更多細節見http://msdn.microsoft.com/en-us/library/ms171398.aspx

相關問題