![](/img/trans.png)
[英]Visual studio project template creating solution file in outer directory
[英]When creating a multiple project template for visual studio is there a way to use parameters in the root template file?
我正在嘗試創建一個多項目模板。 我希望子項目名稱包含解決方案名稱。 我嘗試了以下但是$ safeprojectName $由於某種原因在根模板中不起作用。 它嘗試使用名稱中的$ safeprojectName $創建文件夾,而不是實際的項目名稱。
<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>
我已經對此做了大量的閱讀,並且已經使用IWizard接口創建了一個程序集,該接口創建了一個參數$ solutionName $。 然后我使用了以下模板。
<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>
然而,這也會因同樣的問題而失敗。 我是不是想做不可能的事? 對此的任何幫助都是最受歡迎的。
從Visual Studio 2013 Update 2開始,您現在可以在根.vstemplate文件中使用ProjectTemplateLink元素上的CopyParameters屬性。 根模板中定義的任何參數都將在鏈接模板中以“ext_”前綴提供。
例如,如果根模板定義了一個參數$ Foo $,那么參數$ ext_Foo $將在具有相同值的鏈接項目中可用。
有關更多詳細信息,請參見http://msdn.microsoft.com/en-us/library/ms171398.aspx 。
您可能需要查看Guidance Automation Toolkit 。 那里有相當數量的消化,但它可以做的一部分是在多項目模板上放置基於向導的UI。
如果您想看一個示例,請查看服務工廠 ,它可以部分基於向導創建整個解決方案結構。
是的,您需要在根模板向導中使用靜態字典,這將由子模板的向導實現使用:
根模板中的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;
您可以在此處獲得完整的示例: 帶向導的多項目模板:Visual Studio 2010示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.