Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Maximize Your Productivity with Project Item Templates : Page 3

Create your own Windows Forms, Web Forms, or class templates to reuse code and maximize your productivity in Visual Studio 2003.


advertisement
Step 3: Updating the Support Files
When you select a template from the Add New Item dialog box, Visual Studio executes a JavaScript script to copy the template, perform the name substitutions, and add the resulting item to your project. This script is located in the wizard directory that you copied in Step 1.

For VB, you need to manually update that script to provide it with the name of your template file. The script is located in \Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\BOTemplateWiz\Scripts\1033\default.js. You need to edit the line defining the template file name as follows:

var strTemplateFile = strTemplatePath + "\\BOTemplate.vb";

In C#, the script looks in an information file for the template file name so instead of updating the script directly, you need to update the information file. Open the information file in \Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards\BOTemplateWiz\Templates\1033\Templates.inf. Edit this file to define your template file name as follows:

BOTemplate.cs

Your wizard directory is then ready. It contains your template and the script file that will process your template. Next you need to create a wizard file that points to your wizard directory so Visual Studio can find your wizard directory.

Step 4: Creating a Wizard File
Each wizard directory (defined in Step 1) needs an associated wizard file that defines the name of the wizard directory and other parameters needed by Visual Studio to find and process your template. Again, to make this step easy, simply copy a similar wizard file as a starting point.

For VB, copy the Class.vsz file in \Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBProjectItems to BOTemplateWiz.vsz. Then edit the wizard directory name in the file as follows:



VSWIZARD 6.0 Wizard=VsWizard.VsWizardEngine.7.1 Param="WIZARD_NAME = BOTemplateWiz" Param="WIZARD_UI = FALSE" Param="PROJECT_TYPE = VBPROJ"

For C#, copy the CSharpAddClassWiz.vsz file in \Program Files\Microsoft Visual Studio .NET 2003\VC#\CSharpProjectItems to BOTemplateWiz.vsz. Then edit the wizard directory name in the file as follows:

VSWIZARD 7.0 Wizard=VsWizard.VsWizardEngine.7.1 Param="WIZARD_NAME = BOTemplateWiz" Param="WIZARD_UI = FALSE" Param="PROJECT_TYPE = CSPROJ"

Your wizard file then has the information it needs to find and process your template. Now you just need to provide the name of the wizard file to the Add New Item dialog box. When you select the template from the Add New Item dialog box, it will use the wizard file to locate your template, execute the associated script, and add the project item to your project.

Step 5: Updating the VSDir File
The Add New Item dialog box uses a set of Visual Studio directory (VSDir) files to determine how each project item is to appear in the dialog and how to process an item when the user selects it.

After you have defined all of the required template, script, and wizard files for your new template, you need to create an entry for your template in the appropriate VSDir file so it appears as a project item in the Add New Item dialog box.

The Add New Item dialog box uses several different VSDir files, including one for the basic project items and one for each folder as shown in Figure 1. You can add your template to any number of these files, depending on how you want your template to appear in the Add New Item dialog box.

For this example, the item will only be added to the basic project items list. Edit the LocalProjectItems.vsdir file located in \Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBProjectItems\Local Project Items for VB and in \Program Files\Microsoft Visual Studio .NET 2003\VC#\CSharpProjectItems\LocalProjectItems for C#. Add a new line to the file that defines the information regarding your template.

For VB:

..\BOTemplateWiz.vsz|0|Deb's BO Template|15|Standard BO Template|{164B10B9-B200- 11D0-8C61-00A0C91E29D5}|4510|0|BOTemplate.vb

For C#:

..\BOTemplateWiz.vsz|0|Deb's C# BO Template|15|Standard BO Template|{FAE04EC1-301F- 11d3-BF4B-00C04F79EFBC}|4515|0|BOTemplate.cs

Each line contains the data elements needed by Visual Studio to define how the template is to appear in the Add Items dialog box and how the template should be processed when the user selects it. Each of the data elements are delimited by the pipe character (|) and described in Table 1.

Table 1: The fields in a VSDir file provide information to the Add New Item dialog box.

Field

Description

..\BOTemplateWiz.vsz

Directory location and name of the wizard file used to locate the project item template and add the item to the project.

0

Optional GUID representing the product that has a DLL containing the resources needed by the wizard.

Deb's BO Template

Optional name used within the Add New Item dialog box to define the template as shown in Figure 1. This can be a string or a resource ID.

15

Integer representing the sort order for where the template should appear in the Add New Item dialog box.

Standard BO Template

Description of the template as it will appear in the Add New Item dialog box when the item is selected. (See the status bar area of Figure 1.) This can be a string or a resource ID.

{GUID}

Full path to a DLL or EXE file or a GUID of a product that has a DLL file that contains an icon to load for the wizard. In this example, the value was copied from the line for the standard class template.

4510

Optional resource ID of the icon to display. If not defined, the default icon for the DLL file (see the prior table entry) will be used. In this example, the value was copied from the line for the standard class template.

0

Flags identifying specialized user interface behavior. (See the online help system under "VSDir Files" for more information.)

BOTemplate.vb

The default name for the template displayed in the Name field in the Add New Item dialog box, as shown in Figure 1.




Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date