简体   繁体   中英

VS2017 Item Template not showing up in Xamarin project

I created a new VS2017 project template because the C# 'Class' template for Xamarin.Android adds way too much usings for my tastes. Here's the .vstemplate file:

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
  <TemplateData>
    <DefaultName>Class.cs</DefaultName>
    <Name>Class</Name>
    <Description>An unfancy C# class.</Description>
    <ProjectType>CSharp</ProjectType>
    <SortOrder>10</SortOrder>
    <Icon>__TemplateIcon.ico</Icon>
  </TemplateData>
  <TemplateContent>
    <References />
    <ProjectItem SubType="Code" TargetFileName="$fileinputname$.cs" ReplaceParameters="true">Class.cs</ProjectItem>
  </TemplateContent>
</VSTemplate>

I can't figure out why, but this item template won't show up in my Xamarin.Android project. However, the template does show up when I create a new .NET Core/Framework project and click Add > New Item .

Any clue what's causing this? I've been staring at MSDN/StackOverflow questions for half an hour but none of them seem to help with this.

I'm using the latest stable build of VS2017, which I think is 15.2.

You need the <AppliesTo/> element. See AppliesTo

Using your template you would do:

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
  <TemplateData>
    <DefaultName>Class.cs</DefaultName>
    <Name>Class</Name>
    <Description>An unfancy C# class.</Description>
    <ProjectType>CSharp</ProjectType>
    <AppliesTo>CSharp</AppliesTo>
    <SortOrder>10</SortOrder>
    <Icon>__TemplateIcon.ico</Icon>
  </TemplateData>
  <TemplateContent>
    <References />
    <ProjectItem SubType="Code" TargetFileName="$fileinputname$.cs" ReplaceParameters="true">Class.cs</ProjectItem>
  </TemplateContent>
</VSTemplate>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM