locked
Visual Studio Template RRS feed

  • Question

  • I cannot get my class template to show up when I am trying to add a new item in a Shared Project. It shows up on a C# console application project.
    Wednesday, April 18, 2018 8:39 PM

Answers

  • Hi,

    Add a <TemplateID> element and a <AppliesTo>CSharp + SharedAssetsProject</AppliesTo> element in the <TemplateData> section.

    the code for my template is below:

    <VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
      <TemplateData>
        <DefaultName>MyClass.cs</DefaultName>
        <Name>MyClass</Name>
        <Description>My customized class template.</Description>
        <ProjectType>CSharp</ProjectType>
        <TemplateID>MyTemplate.MyClass</TemplateID>
        <AppliesTo>CSharp + SharedAssetsProject</AppliesTo>
        <SortOrder>10</SortOrder>
        <Icon>__TemplateIcon.ico</Icon>
      </TemplateData>
      <TemplateContent>
        <References />
        <ProjectItem SubType="" TargetFileName="$fileinputname$.cs" ReplaceParameters="true">Class1.cs</ProjectItem>
      </TemplateContent>
    </VSTemplate>

    Add MyClass.zip to C:\Users\xxxxxxxxx\Documents\Visual Studio 2017\Templates\ItemTemplates, restart visual studio and check it again.

    Best regards,

    Joyce


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, April 24, 2018 9:23 AM

All replies

  • Please be more specific.


    Sam Hobbs
    SimpleSamples.Info

    Wednesday, April 18, 2018 9:11 PM
  • Hi,

    Welcome to MSDN forum.

    What's your version of visual studio?

    I test with visual studio 2015 and visual studio 2017, right click on shared project in solution explorer ->add new item, class template is available.

    Please repair visual studio,  open visual and create a new shared project and check it if the issue persists.

    Best regards,

    Joyce


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 19, 2018 6:13 AM
  • My version of Visual Studio is 2017.  I created my own custom template to add a class object.  When I right click on Add New Item on a folder I created in a Shared Project, my template does NOT show up on the Add New Item dialog menu as shown below:

    However, when I try to add a new item into my C# Console Application project, the Add New Item contain my custom template and allows me to add it to my project as shown below:

    Can you help determine why it shows up in one project and not the other?  the code for my template is below

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

    Your support is greatly appreciated! 

    Thanks,

    Tien

    Thursday, April 19, 2018 4:17 PM
  • Please see details I provided below...
    Thursday, April 19, 2018 4:45 PM
  • Hi,

    Thank you for the update.

    You can have a look at the thread:

    https://stackoverflow.com/questions/35065060/item-template-for-shared-project-in-visual-studio

    add<AppliesTo>CSharp</AppliesTo> element in the <TemplateData> section.

    After digging around in Visual Studio's installed templates, I discovered that to add a template to a sub-category, such as Shared Project under C#, one needs to create a folder with the same name as the sub-category and place the template in that folder.

    Best regards,

    Joyce


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, April 20, 2018 10:02 AM
  • Hi Joyce,

    I added the AppliesTo line and it does not make a difference.  Would you be able to provide me with specific details/snapshot of the vstemplate file?

    Best regards,

    -Tien

    Saturday, April 21, 2018 3:45 AM
  • Hi,

    Add a <TemplateID> element and a <AppliesTo>CSharp + SharedAssetsProject</AppliesTo> element in the <TemplateData> section.

    the code for my template is below:

    <VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
      <TemplateData>
        <DefaultName>MyClass.cs</DefaultName>
        <Name>MyClass</Name>
        <Description>My customized class template.</Description>
        <ProjectType>CSharp</ProjectType>
        <TemplateID>MyTemplate.MyClass</TemplateID>
        <AppliesTo>CSharp + SharedAssetsProject</AppliesTo>
        <SortOrder>10</SortOrder>
        <Icon>__TemplateIcon.ico</Icon>
      </TemplateData>
      <TemplateContent>
        <References />
        <ProjectItem SubType="" TargetFileName="$fileinputname$.cs" ReplaceParameters="true">Class1.cs</ProjectItem>
      </TemplateContent>
    </VSTemplate>

    Add MyClass.zip to C:\Users\xxxxxxxxx\Documents\Visual Studio 2017\Templates\ItemTemplates, restart visual studio and check it again.

    Best regards,

    Joyce


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, April 24, 2018 9:23 AM