Creating Custom Templates

See Also

Any text file, such as .htm, .asp, or .java files, can be used as a template for creating new similar project items. When creating a file, you can base it on a standard product template or use one of your own custom templates. Creating a template consists of some or all of these steps:

Customizing Template Files

You can place text in a template file, such as source code, URLs, and script, that will be copied into the new project item you create from the template file.

You can place source code, URLs, text, script, and other formatting in the template files that will appear in each file you create based on the template file.

A template can be any text file such as an:

Note   The Template wizard recognizes text files based on the content type registered for the file extension. If the wizard does not recognize a particular file, you need to register the file extension as a text file in the system registry. For more information, see "To create or modify a file type" in Windows Help.

The Template wizard allows you to prompt users for information based on the parameters you include in your template files. You can create your own custom prompts or you can use one of the unique functions recognized by the Template wizard.

To prompt the user for input

Note   When you add an .htm or .asp file to a Visual InterDev Web project, Visual InterDev automatically applies the default theme and layout for the project to the page if one has been specified.

Creating a .vsz File

In order to add your files to a project using the Template wizard, you must create a .vsz file. A VSZ file is a text file used to launch wizards. The VSZ file contains information that identifies a wizard and provides custom information for it. For more information about .vsz files, see Creating VSZ Files.

Note   If you create single template files that do not contain any user prompts, you can place the file in the default project items directory for the product. Single template files that do not contain user prompts do not require .vsz or .vsdir files.

To launch the Template wizard, the .vsz file must contain the following text:

VSWizard 6.0
Wizard=VIWizard.CTemplateWizard
Param=<directory path for template files>

For example, if you created a template that contains two files, MyTemplate.htm and MyTemplate.asp, and placed them in c:\Program Files\Microsoft Visual Studio\Vintdev98\Templates\MyTemplate directory, the .vsz file would read:

VSWizard 6.0
Wizard=VIWizard.CTemplateWizard
Param=c:\Program Files\Microsoft Visual Studio\Vintdev98\Templates\MyTemplate

If you created a template that contains two files, MyTemplate1.java and MyTemplate2.java, and placed them in c:\Program Files\Microsoft Visual Studio\VJ98\Templates\MyTemplate directory, the .vsz file would read:

VSWizard 6.0
Wizard=VIWizard.CTemplateWizard
Param=c:\Program Files\Microsoft Visual Studio\VJ98\Templates\MyTemplate

You can optionally indicate which template file should open automatically in the editor when the Template wizard has finished. For example, you can specify that MyTemplate1.java open in the editor by adding a second Param statement to the end of the .vsz file:

Param=MyTemplate1.java

For more information, see "Adding Templates to Projects" later in this topic.

Creating a .vsdir File

You can optionally create a VSDIR file or modify an existing .vsdir file to specify the display of .vsz files in the Add Items dialog box. A VSDIR file is a text file that is used to provide information to the Add Item dialog and the New Project dialog boxes. The VSDIR provides information about the items these dialog boxes display, such as the names, descriptions, and the icon to display.

You can have multiple VSDIR files in a single directory; however, generally one VSDIR file is used to contain information for multiple wizards, folders, or templates.

Note   If you have multiple .vsdir files in a single directory, do not duplicate the same file information in multiple .vsdir files.

For example, you could create a .vsdir file like the following:

MyTemplate.vsz|{0}|MyTemplate|30|Create a new custom file.|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|287|3|MyTemplate

Note   The .vsdir file contains line-oriented records.

For more information about .vsdir files, see Creating VSDIR Files.

Adding Templates to Projects

You must place your .vsz and .vsdir files in the correct directories so that the Add Items dialog box can locate the files.

Note   If you create single template files that do not contain any user prompts, you can place the file in the default project items directory for the product. Single template files that do not contain user prompts do not require .vsz or .vsdir files.

For Visual InterDev, the default project items directory is:

c:\Program Files\Microsoft Visual Studio\VintDev98\Templates\Web Project Items\

For Visual J++™, place .vsz files and single template files in:

c:\Program Files\Microsoft Visual Studio\VJ98\VJProjectItems\Other

You can also create a custom directory under c:\…\VJProjectItems.

Each template should have a separate directory to contain only its template files. If the files for a template are not located in the same directory, the Template wizard can not process them.