HTML

The Visual Studio .NET wizard user interface engine is actually a web browser,
and the various wizard forms that guide you through a process are simply HTML
pages. These HTML pages can be localized, so they are placed in a directory
named after the language ID (1033 for US English). The main HTML file is named
default.htm, although there can be others for additional pages
or tabs in the wizard. In the case of CSharpAddClassWizard, there
are BaseClass.htm and Inheritance.htm.

Images

Images in Visual Studio .NET wizards may be used to show a company logo, user
interface elements, or blank images used as spacers. Any image format supported
by Internet Explorer can be used. Although images may also be localized, CSharpClassWiz
does not use localized images.

Scripts

A Visual Studio .NET wizard may use JScript files to generate user interface
elements, or to process input data to generate template files. Script files
may be localized the same way as HTML files.

Templates

The files generated by the wizard typically start with a template that has
placeholders for variables gathered from the user. Templates may be localized
the same way as HTML and script files. The Templates directory
also includes a file named Templates.inf, whose content is the
name of the actual template file to copy.

In addition to the files in the specified directories, wizards may also make use of components in other directories. For example, CSharpAddClassWizard includes Script.js and Common.js from a completely different location, outside of the wizard's own directory. These script files contain functions used throughout the built-in wizards.

In addition to the wizard components, there are files that have to be created or edited in order to inform Visual Studio .NET of the availability of a particular wizard.

The .vsz File

The .vsz file lives in the VC#\CSharpProjectItems directory, and contains information about how the wizard engine will present the wizard. For more information about the .vsz file, see the Microsoft Help topic.

LocalProjectItems.vsdir

This file, located in the VC#\CSharpProjectItems\LocalProjectItems directory, contains settings for how the Add New Item dialog box will present the new project item. These setting include the icon, its caption, where the template file is located, the default name of the new file, and other settings. Each wizard has a line with the following fields, delimited by pipes:

Relative path to the .vsz file.

GUID of a product containing resources.

Name of the wizard to display in Add New Item dialog box, or resource ID (when prefixed with #) of the string containing the name.

Sort order of the item.

Long description of the wizard, also displayed in the dialog box, or resource ID.

Having pretty much figured out what makes the standard wizards tick, let's start creating our own.

Making It Work

First, the (very simple) requirements. The new wizard will be used to create a C# class that is a subclass of a specific class. The generated class will also depend on two other classes, a data table, and a strongly typed dataset, the names of which we'll collect from the developer. The developer should be able to select the namespace for the class as well as the namespace for the dataset, and make a choice between two difference base classes for the generated class. No other options should be presented to the developer. In the generated code, we'll provide stubs for a few abstract methods that must be overridden, and declare some properties whose return types are the types whose names we collected from the developer.

Those simple requirements out of the way, it's fairly easy to see what needs to be done. Here are the steps to be taken to create the new wizard, CSharpAddCMSimpleBusinessClassWizard:

Copy the CSharpClassWiz directory to CSharpAddCMSimpleBusinessClassWizard.

Create a file called CSharpAddCMSimpleBusinessClassWizard.vsz in VC#\CSharpProjectItems and make its contents the following:

Edit the default.htm file and delete the unneeded Bases.htm and Interfaces.htm files. We'll also make some changes to default.htm.

Delete the template file NewCSharpFile.cs and create a new one called SimpleBusinessClass.cs.

Add the following line to the LocalProjectItems.vsdir file, telling Visual Studio where to find CSharpAddCMSimpleBusinessClassWizard and its support files and resources. Note that I've borrowed the icon from the add class wizard, and used inline text in the file rather than pointing to a resource for other strings.

Restart Visual Studio .NET 2003, and the next time you right-click on a project
and select Add New Item..., you'll see the icon labeled "New Simple Business Class." Click on it, and you'll see the wizard we designed (Figure
2).

Figure 2. Your New Wizard

Conclusion

I've shown you one way to add a New Item wizard to Visual Studio .NET 2003 with a minimum of fuss and precious little code. I hope you find this technique useful as you continue the permanent quest for greater productivity.

Niel Bornstein
is a Senior Architect for Novell's Systems and Resource Management Business Unit specializing in data center automation.