Click here to Skip to main content
Click here to Skip to main content

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

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

Introduction

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.

Background

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>">

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.

Output

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.

License

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

 
GeneralShort and concise Pinmemberswarmt16-Jun-05 15:16 
GeneralRe: Short and concise PinmemberMichael McKechney16-Jun-05 18:14 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 21 May 2004
Article Copyright 2004 by Michael McKechney
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid