Search code examples
c#visual-studio-2015vsixitemtemplate

VS 2015 Item Template for custom file with ability to add on all cross-platform Project/SubProject


Currently one of my requirement is adding specific file with prefix called .zbl to ANY TYPE OF project like 'Shared' , 'class library', UWP and so on. I am following the VSIX approach with ITEM TEMPLATE Project.

The problem is, when you are on NON-Class library projects, you can not find your ITEM on Project->Add new item -> new your custom item for example "Page.zbl"

This issue is coming from HERE as MSDN says Item template can be specified in 4 categories : Windows / Office /Database/Web

also you can not set more than one of above values in template file, SO How is it possible to add an Item Template to VS 2015 which will be accessible to all project types ?

here is my sample VS ItemTemplate:

<VSTemplate Version="3.0.0" Type="Item">  
<TemplateData>  
    <Name>Page1</Name>  
    <Description>An empty Zebble file</Description>  
    <Icon>zebble.ico</Icon>  
    <ProjectType>CSharp</ProjectType>  
    <ProjectSubType>??????</ProjectSubType> : HERE IS THE ISSUE 
    <DefaultName>Page1.zbl</DefaultName>  
</TemplateData>  
<TemplateContent>  
    <ProjectItem>Page.zbl</ProjectItem>  
</TemplateContent>  


Solution

  • Assumed VS 2015[Update 3] is current stable development environment, first lets have a look at the VS strucure at these path (win 10):

    1/ C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\

    There are some folders which represent current item-templates for VS-IDE, as far as I tested you can not add your cusotm folder there to seprate your template,Therefore you need to select one as reference like CSharp(you need this for TemplateID),

    2/ Next, you need to set following configuration FOR TemplateData node on on your Item-Template project :

    <?xml version="1.0" encoding="utf-8"?>
    <VSTemplate Version="3.0.0" **Type="Item"**  xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:sdk="http://schemas.microsoft.com/developer/vstemplate-sdkextension/2010">
    <TemplateData>
        <Name>YOUR ITEM  </Name>
        <Description>Zebble Page Tempalte </Description>
        <Icon>ZebblePageItemTemplate.ico</Icon>
      **<ProjectType>CSharp</ProjectType>**
        <RequiredFrameworkVersion>2.0</RequiredFrameworkVersion>
      **<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>**
        <DefaultName>Cross-platform Page.zbl</DefaultName>
      **<TemplateID>Microsoft.CSharp.TextFile</TemplateID>**
      **<AppliesTo>CSharp + WindowsXaml + WindowsXamlPage + WindowsXamlCodeBehind + MultiTarget</AppliesTo>**
        <CreateInPlace>true</CreateInPlace>
        <Hidden>false</Hidden>
        <CreateNewFolder>true</CreateNewFolder>
        <LocationField>Enabled</LocationField>
        <SpecialTemplateType>EmptyShared</SpecialTemplateType>
       <EnableLocationBrowseButton>true</EnableLocationBrowseButton>    
    

    MyPage.zbl

    3/ Other configuration should be applied on template propertied and Vsix reference via Propery window like these: Cross-Platform will be a node name of VSProject->AddNewItem->(LeftMenu category)

    Here is Vsix project which referece to item-template as asset

    and Finally your result would be : VS result

    if you cannot see the result you need to restart your VS by running the below command in CMD with Administrator mood

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE>devenv /setup