Click here to Skip to main content
14,637,429 members
Articles » Development Lifecycle » Installation » General
Posted 20 May 2004


42 bookmarked

Visual Studio .NET "Add New Item" Custom Template Installer

Rate this:
4.15 (12 votes)
Please Sign up or sign in to vote.
4.15 (12 votes)
20 May 2004
Tool to automate the installation of Custom Item Templates in Visual Studio .NET.


Adding a project template entry into Visual Studio .NET's "Add New Item" window seems like it should be a simple process, until you try it. The multi step, multi file process is cumbersome and error prone. Chris Sells' article clearly defines the process, but if you have to add more than one template, you soon realize there has to be a better way.


Like all developer tools, this one came to being to make my life easier. I had several project item templates I wanted to reuse and wasn't about to manually process each one. The nuances of creating vsdir, vsz, js and inf files, inserting items in pipe delimited strings (yes, I said pipe delimited!), and putting the 5 or 6 files in a proper directory structure is too much to expect anyone to get right each time. After studying Chris' article, I boiled down the process into a few manageable items and started coding.

Since I wanted to be able to install multiple templates at a time in a simple fashion, I chose a console application that uses XML files as input. This way, a simple batch file can install as many templates as needed with one command. The XML input requires the basic information needed to create the project item, and isolates the user from knowing how or where to create the required files.

The Simplified Process

The developer now has only two tasks to complete before installing the custom template:

  1. Create the template file(s) themselves. (There are many articles on the details of creating these item templates. This article shows a good example for a custom web form: MSDN.)
  2. Define a few details in the XML file. See the XML definition below.

The gory details are handled by the installer application.

The XML File

<?xml version="1.0" encoding="utf-8" ?>
<NewProjectItemTemplate xmlns="<a href="http://newprojectitem/NewProjectItemDefinition.xsd">http://NewProjectItem/NewProjectItemDefinition.xsd</a>">

      Name="" ImageType="" ProjectType="" 

      ProjectSubType="" NewSubTypeName="" />

The application uses a typed DataSet to read the XML input file and uses the resulting object properties to create the project item. As it stands today, you need one XML file per project item you want to install.

Element and attribute definitions:

  • Name: what you want to call your new project item (e.g., CsharpAddNewWidget)
  • ImageType: which icon to use to display the project item in the "Add New Item" window. Allowable values: WebControl, WebForm, XmlFile, Class, Component, WebService, WebUserControl, WindowsService, WindowsForm, WindowsUserControl, WindowsCustomControl. (Note: all enumerated values are fully defined in the XSD file.)
  • ProjectType: Determines which project type folder the project item will display under, Local Project and/or Web Project. Allowable values: LocalProjectItems, WebProjectItems, Both.
  • ProjectSubType: Determines which project item subfolder the item will display under. Allowable values: Code, UI, Data, Resources, Utility, New.
  • NewSubTypeName: If you chose "New" for ProjectSubType, provide the name of the new folder to create and display in the "Add New Item" window. Note: if the new type already exists, the project item will be placed in it, leaving the existing entries alone.
  • ShortDescription: The name to display with the icon in the "Templates" list view.
  • LongDescription: The name to display in the info area when the template icon is selected.
  • DefaultFileName: The default file name to put in the "Name" text box of the "Add New Item" window.
  • CodeFileTemplatePath: The path of where to find the code template to use. (If a full path is not provided, the app looks in its directory for the file.)
  • WebFormTemplatePath: If you are creating a custom web form, this is the path of where to find that file. (If a full path is not provided, the app looks in its directory for the file.)

Command Line

The command line processing is straight forward and the help file can be viewed with a "/?" flag. The installer takes up to 3 parameters.

  1. The XML input template file (full path if not co-located with the executable)
  2. The path to Visual Studio .NET 2003 (optional if installed in the default location of C:\Program Files\Microsoft Visual Studio .NET 2003.)
  3. "/s" - silent mode. When running in a batch file, it doesn't wait for user input to run the next statement.


For each run of the installer, you will get a simple progress output letting you know what the installer is doing. If you are re-installing a custom template, you will also get two "removing" lines as the installer deletes the old templates and add the new ones. Once complete, you can open the "Add New Items" window, see your new entries, and add them to your projects.

Image 1


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Michael McKechney
Web Developer
United States United States
No Biography provided

Comments and Discussions

QuestionSafely removing new items? Pin
MrGlover14-Jun-06 15:27
MemberMrGlover14-Jun-06 15:27 
GeneralVery Helpful Pin
timbochu22-Feb-06 20:15
Membertimbochu22-Feb-06 20:15 
QuestionCould it work for WebUserControls? Pin
valdonano26-Aug-05 4:08
Membervaldonano26-Aug-05 4:08 
AnswerRe: Could it work for WebUserControls? Pin
Michael McKechney5-Sep-05 15:04
MemberMichael McKechney5-Sep-05 15:04 
GeneralRe: Could it work for WebUserControls? Pin
Rogerio Meneghelo Apezzatto12-Mar-08 6:17
MemberRogerio Meneghelo Apezzatto12-Mar-08 6:17 
Generalonly for C#... Pin
TCDooM27-Jul-05 23:22
MemberTCDooM27-Jul-05 23:22 
GeneralShort and concise Pin
vannich16-Jun-05 15:16
Membervannich16-Jun-05 15:16 
GeneralRe: Short and concise Pin
Michael McKechney16-Jun-05 18:14
MemberMichael McKechney16-Jun-05 18:14 
GeneralVery nice article... Pin
Maruis Marais21-May-04 14:56
MemberMaruis Marais21-May-04 14:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.