views:

13

answers:

2

I'm currenlty working on an add-in and require the functionality to add custom item templates to a project programatically.

I'm currently installing the templates (which are of a .zip format) in ..\Visual Studio 2010\Templates\ItemTemplates\.

From within the add-in I then call the following code:

string templateLocation = (solution as Solution2).GetProjectItemTemplate(templateName, language);
projectToAddTo.ProjectItems.AddFromTemplate(templateLocation, nameOfNewItem);

If the item template is for a C# file then if i use "CSharp" for the language variable and place the template in the Language Folder "Visual C#" or "Visual Web Developer\Visual C#" then this all works fine; the template is discovered and implemented correctly within Visual Studio.
However if I create a JScript or HTML template, the GetProjectItemTemplate method throws an exception if I supply the language as "JScript" or "HTML". I've tried placing the templates in both "ItemTemplates\JScript(HTML)" and "ItemTemplates\Visual Web Develerop\JScript(HTML)" with no luck.

Anyone have any ideas about what I'm doing wrong, what languages are supported for these custom item templates, what the language parameter and folder location should be?

A: 

From having looked into this a bit more it seems that the parameter Language in string Solution2.GetProjectItemTemplate(string TemplateName, string Language) is actually the language type of the project which the item template is targetting. Hence whether the actual item in the template is a java file or an html file, the project would still be CSharp or VisualBasic and so that is what should be passed in as the Language parameter.

Furthermore, in the location for custom item and project templates, it doesnt matter what the folder is called, be it Visual C#, Visual Basic, Visual Web Developer\JScript. The name of the folders just affects how it appears in the Add New Item Dialog and how its stored in the cache.

Also, the TemplateName parameter you specify when calling GetProjectItemTemaplate should have the full reletive path from beneath the ItemTemplates folder. Although it will work without it, if you have more than one template with the same name in different locations then you'll get the first one returned by VS.

gouldos
A: 

My suggestion is to take an HTML or JS and use VS's own menu to export this as a template. Then, unzip the template and look for the language parameter in the .vstemplate file.

Dmitri Nesteruk