1

I used visual studio 2012 "Export Template..." to create a few single file C# item templates for myself. The ZIP files show up in My Exported Templates, and I can move them into the Templates directory. When I then create a C# console application the templates show up there just fine.

However, this is for a windows store application. And I created these guys to add to my windows store application. However, the Add Items dialog box in VS2012 does not how them there. I am guessing there is something wrong with the XML that VS2012 has generated. Anyone know?

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
  <TemplateData>
    <DefaultName>KonaViewModelWithBack.cs</DefaultName>
    <Name>KonaViewModelWithBack</Name>
    <Description>&lt;No description available&gt;</Description>
    <ProjectType>CSharp</ProjectType>
    <SortOrder>10</SortOrder>
    <Icon>__TemplateIcon.ico</Icon>
  </TemplateData>
  <TemplateContent>
    <References />
    <ProjectItem SubType="Code" TargetFileName="$fileinputname$.cs" ReplaceParameters="true">ConnectToRTMViewModel.cs</ProjectItem>
  </TemplateContent>
</VSTemplate>
4

1 回答 1

2

After hunting around for XML elements in the VS2012 class file, I stumbled on TemplateID. If you look there you'll notice that it refers to a TemplateGroupID.

If you look at the TempmlateGroupIDs(VsTemplate) for a WinRT based app (see the registry location, along with the BTW note below) you'll find that "WinRT-Managed" is listed. If you change the template file to add a TemplateGroupID set to that, then VS2012 will find it correctly:

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
  <TemplateData>
    <DefaultName>KonaViewModel.cs</DefaultName>
    <Name>Kona View Model With Back Button</Name>
    <Description>A Kona based View Model which implements a go back button ICommand</Description>
    <ProjectType>CSharp</ProjectType>
    <SortOrder>10</SortOrder>
    <RequiredFrameworkVersion>2.0</RequiredFrameworkVersion>
    <NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
    <Icon>__TemplateIcon.ico</Icon>
    <TemplateGroupID>WinRT-Managed</TemplateGroupID>
  </TemplateData>
  <TemplateContent>
    <References />
    <ProjectItem SubType="Code" TargetFileName="$fileinputname$.cs" ReplaceParameters="true">ConnectToRTMViewModel.cs</ProjectItem>
  </TemplateContent>
</VSTemplate>

BTW, the docs at the TemplateID msdn page are incorrect, at least on my Win8 Pro with VS2012 Pro up-to-date installation. The registry info displayed there actually shows up in the DEFAULT user hive, not the LOCAL_MACHINE hive).

于 2013-02-27T06:21:26.743 回答