crush
crush

Reputation: 17033

Custom ItemTemplate does not appear in Visual Studio 2015 Add New Item dialog

I have viewed this question and it did not solve my problem.

I'm attempting to create a new ItemTemplate in Visual Studio 2015. I started out by creating the template in Visual Studio, then using the Export Template option from the File menu.

I selected "Item template" from the Export Template Wizard, chose my project, and selected the file that would serve as the template. I filled out the template options, and clicked "Finish" with "Automatically import the template into Visual Studio" and "Display an explorer window on the output files folder" checked.

The explorer window that opened showed my template in a zip archive. I navigated to %My Documents%\Visual Studio 2015\Templates\ItemTemplates and found the zip archive was also in that folder.

I then went to Add New Item dialog, but could not find my template listed in any category, or the main Visual C# Items category.

I unzipped the archived and found the following for the files included within:

MyTemplate.vstemplate

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

Template.cs

using System;
using System.Linq;

namespace $rootnamespace$
{
    public partial class $safeitemname$
    {
        public void $safeitemname$()
        {
            throw new NotImplementedException();
        }
    }
}

What I've Tried

I've tried opening a Developer Command Prompt for VS2015 as an administrator and entering the following commands (not one after the other):

devenv /installvstemplates
devenv /setup
devenv /resetsettings

I've tried restarting my PC and Visual Studio instance multiple times.

I've tried manually clearing the cache folders and rebuilding them (despite the fact that they have nothing to do with custom ItemTemplates as far as I can tell).

As I've read here, here, and here, it should simply read from the %My Documents%\Visual Studio 2015\Templates\ItemTemplates automatically without even needing to close Visual Studio.

I've checked my Tools > Options > Projects and Solutions paths for User item templates locations and it is correct. I even pasted it into the explorer window address bar to be sure.

I've tried placing the .zip archive at various sub levels of the ItemTemplates folder.

I've tried placing the .zip archive in older versions of VS ItemTemplates folders.

I have exhausted every MSDN article and blog I could find. They all seem to indicate that the steps I have tried should've already worked.

What else can I do? Has anyone else encountered and solved this problem?

Please let me know if any additional information could help with this problem

My build of Visual Studio is 14.0.23107.0

Upvotes: 4

Views: 2950

Answers (1)

crush
crush

Reputation: 17033

I wanted to share what I was doing wrong just in case someone else gets through all of the tutorials and documentation out there and still hasn't figured it out.

I was zipping the folder that was created when extracting the compressed archive generated by the Export Template process. This causes the structure of the compressed archived to look something like:

MyTemplate.zip
|-MyTemplate
  |-MyTemplate.vstemplate
  |-MyCodeFile.cs
  |-MyIcon.ico

This extra layer of directories causes Visual Studio not to be able to read the template.

What you want is a structure like:

MyTemplate.zip
|-MyTemplate.vstemplate
|-MyCodeFile.cs
|-MyIcon.ico

If you are using Windows built-in compression Send to > Compressed (zipped) folder, then be sure to select the files themselves, and not the directory that is created when you decompress the archive that was created by the Export Template process.

Upvotes: 5

Related Questions