VSX: ProjectFlavor-only item VSTemplates?
In Visual Studio 2005, 2008, and 2010, is it possible to define an Item Template that only appears in the Add Item dialog for projects of a particular ProjectFlavor? I'd rather not clutter all of the other unrelated projects' Add Items dialog if I can help it.
Seems that the <ProjectType>CSharp</ProjectType>
is a fixed enumeration and I can't find any place for a ProjectFlavor guid or otherwise.
I don't see any examples of other products showing such restraint, but I want to make sure.
=====
OK, Aaron's tip is very promising but my first attempt is unsuccessful.
In the .vstemplate:
<TemplateData>
<Name>MyProject A File</Name>
<Description>MyProject A File to do stuff</Description>
<Icon>A.ico</Icon>
<TemplateID>TemplateID_A</TemplateID>
<TemplateGroupID>MyTemplateGroupID</TemplateGroupID>
<ProjectType>CSharp</ProjectType>
<RequiredFrameworkVersion>2.0</RequiredFrameworkVersion>
<SortOrder>20</SortOrder>
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
<DefaultName>Template_A.cs</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<ShowByDefault>false</ShowByDefault>
</TemplateData>
<TemplateContent>
<ProjectItem ReplaceParameters="true">Template_A.cs</ProjectItem>
</TemplateContent>
And on the package.cs:
// [Pro开发者_运维知识库videProjectItem(typeof(MyProjectFactory), "MyTemplateGroupID",
// @"Templates\ProjectItems", 600)] // Took this out.
[ProvideProjectFactory(typeof(MyProjectFactory),
"My Project", "My Project Files (*.csproj);*.csproj",
null, null, @"Templates\Projects",
LanguageVsTemplate = "CSharp",
NewProjectRequireNewFolderVsTemplate = true,
TemplateGroupIDsVsTemplate="MyTemplateGroupID",
TemplateIDsVsTemplate = "TemplateID_A,TemplateID_B")]
public sealed class MyPackage : Package { ... }
Yes this is possible and there are a few item templates "in the box" that do this. For example, you'll notice that the C# or VB item templates for WPF items (Page, Window, FlowDocument, etc...) only appear if you're working with a WPF-flavored project.
The trick is to specify the same TemplateGroupID in each vstemplate file, and then specify this same TemplateGroupID in the registration of your project flavor.
精彩评论