Research on custom project templates based on vs. net

Source: Internet
Author: User
   Introduction

In actual development, software enterprises often want to reuse mature technologies as much as possible and integrate them into developers' tools. Vs. NET provides many wizard template classes. However, if you want to create a custom wizard template, you need to write a lot of code in the past by creating an idtwizard application. In fact, you can easily solve this problem by directly modifying and replacing the template file in vs. net. The following describes how this method works and provides a specific example.

  Principle

Vs. Net wizard templates are mainly divided into project templates and project templates. When selecting a project template,. net will automatically generate multiple different types of project files, and select the project item template to generate only one file (multiple files will exist when the code-behind file exists ). This section describes how to create a project template. To study the. NET wizard project folder, you can find two types of important files

. Vsdir File

This file defines the items to be displayed in the Wizard project and the properties to be displayed in the dialog box, such as name, description, icon, and default item file name. The corresponding. vsz file describes each of the wizard items.

. Vsz File

This file defines a COM component name (this COM component tells Visual Studio what type of wizard needs to be created) and the parameters (such as the file name) that the component needs to accept ).

These two types of files and their corresponding components are required to create a Project Wizard. Figure 1 shows a structure chart between the three.


Figure 1

Therefore, we can make it clear that you only need to directly modify and replace the template file to easily create a custom wizard template.

  Example

To illustrate this method, create a Project Wizard template named myreport and add a frmreport. CS file. 2 after creation.


Figure 2

(1) In the Vs. net installation directory, find the project template class directory to be added. For example, VC # \ csharpprojectitems is the directory where the C # Project template is located.

(2) create a. vsz file to set the project template wizard, such as csharpaddmyreportwiz. vsz. Enter the following content:

Vswizard 7.0
Wizard = vswizard. vswizardengine
Param = "wizard_name = csharpaddmyreportwiz"
Param = "wizard_ui = false"
Param = "project_type = csproj"

(3) In the Add new project dialog box, the item template hierarchy is determined by the projectitems directory. Select the directory location of the template to be added and add one under the directory. and associate it with the previously created vsz file. In the projectitems \ localprojectitems \ UI directory, add a mywiz. vsdir file and enter the following content:

.. \.. \ Csharpaddmyreportwiz. vsz | {FAE04EC1-301F-11d3-BF4B-00C04F79EFBC} | HR Textile Industry General Report | 0 | provides the textile industry common format report production, printing and data exchange functions of the interface | {FAE04EC1-301F-11d3-BF4B-00C04F79EFBC} | 4534 | 0 | frmreport. CS

Note: here, the | symbol is divided into several different attributes. The first is the relative path of the vsz file we created earlier. The second is a brief description of the add new project dialog box, the complete description (also displayed in the dialog box) is listed in 5th items, and 4th items are sorted in order. The smaller the description, the closer it is to the top. These are important for adding custom project items. The last entry indicates the file format generated and added to this project. The mywiz. vsdir file generated here is only displayed in the directory we set. to display it in the global directory, copy the file to the localprojectitems directory and update the relative path.

(4) Once a new project template is set up, the template must be output in the Wizard. The template information is placed under the template category we have created. For example, VC # \ Vc # wizards is where the C # wizard is located. The directory structure of the template should be 3.


Figure 3

The template \ 1033 directory contains a templates. inf file, which is the template file for generating template items. This file uses the Wizard to generate a script to generate a wizard. The following is a templates. the INF example contains a description of the file: report1.asmx. the general project will create a file in the Add dialog box, that is, we are working on templates. A single file contained in the INF file. When running, the wizard generates a report1.asmp file in the template folder as the template.

In addition, you can do more in-depth work. for example, you need the Project Wizard to output a custom frm file and the corresponding frm. CS file, you can copy the csharpaddformwiz folder and rename it as csharpaddmywebformwiz, and repeat steps 1-4. Then, add another file to the templates. inf file. These processes are not described here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.