tags:

views:

103

answers:

1

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:

// [ProvideProjectItem(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 { ... }
+1  A: 

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.

Aaron Marten
Thanks Aaron, can you please check the additional formatted stuff at the top for a followup?
uosɐſ
Hi Aaron, any further detail on this?
uosɐſ
In the above when you say "In the VSCT" I assume you meant "In the VSTemplate".Try adding LanguageVsTemplate = "CSharp" to the attribute.
Aaron Marten
Aaron, you were right about the VSTemplate. I've corrected the post above. Unfortunately, it it's working. I've posted a more complete code listing. See anything? Thanks!
uosɐſ
Ok, again, I'm awarding you best answer because it will expire, but if you can continue to help I'd appreciate it.
uosɐſ
Sure thing. I think the other missing component here is that you need to override GetGuidProperty in your FlavoredProjectBase-derived class and return your the Guid of MyProjectFactory for __VSHPROPID2.VSHPROPID_AddItemTemplatesGuid. Here's a code example: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.flavor.flavoredprojectfactorybase.aspx
Aaron Marten
That was it!! Thanks!
uosɐſ

related questions