问题
I have created ItemTemplates before in VS2005/2010 and never had any problem.
With VS 2012 Ultimate edition on Windows8, the ItemTemplate I am creating isn't showing up in the Add New Item list.
Tried just the basic steps mentioned here: http://msdn.microsoft.com/en-us/library/tsyyf0yh.aspx
Created a new Windows 8 Store App(xaml) Blank Project. It has a MainPage. I added a TextBlock to the mainpage to make it look different. Then exported the template.
The .zip file gets added to the ItemTemplates folder and My Exported Templates folder but won't show up in the list. I did restart my VS several times but no go.
Any idea? I wonder if I am missing some VS option?
回答1:
I am not sure if it's a bug in VS2012 or I missed something but here's how I was able to get my Template showing up in the Add New Item menu.
1: I unzipped my Template created initially.
2: Opened an default Template that comes with Visual Studio 2012.
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Windows Store\1033\BlankPage
3: Compared the BlankPage.vstemplate with MyTemplate.vstemplate. Made my template file look like this:
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
<TemplateData>
<DefaultName>CustomStoryPage.xaml</DefaultName>
<Name>CustomStoryPage</Name>
<Description>Template for custom storypage</Description>
<TemplateID>Microsoft.CS.WinRT.CustomStoryPage</TemplateID>
<TemplateGroupID>WinRT-Managed</TemplateGroupID>
<ProjectType>CSharp</ProjectType>
<SortOrder>10</SortOrder>
<TargetPlatformName>Windows</TargetPlatformName>
<RequiredPlatformVersion>8</RequiredPlatformVersion>
</TemplateData>
<TemplateContent>
<References />
<ProjectItem ItemType="Page" SubType="Designer" CustomTool="MSBuild:Compile" TargetFileName="$fileinputname$.xaml" ReplaceParameters="true">StoryPageTemplate.xaml</ProjectItem>
<ProjectItem SubType="Code" TargetFileName="$fileinputname$.xaml.cs" ReplaceParameters="true">StoryPageTemplate.xaml.cs</ProjectItem>
</TemplateContent>
</VSTemplate>
4: zipped the folder back again.
Some stuff might be unnecessary above but for now I have my issue fixed. I need to do one by one to find out what exactly are required items.
回答2:
Adding the <TemplateGroupID>WinRT-Managed</TemplateGroupID> line fixed this for me.
来源:https://stackoverflow.com/questions/13325950/custom-itemtemplate-not-showing-up-in-visual-studio-2010-add-new-item