To be happy: Visual Studio. NET Custom Wizards

Source: Internet
Author: User
Tags copy object model thread web services visual studio
Visual visual Studio. NET supports a number of built in project types and wizards that generate skeleton projects and Sol Utions depending on the type of application the developer intend to build. These are project templates are an excellent way to automate the basic plumbing required for very common project types, such a s Windows applications, Class libraries and Web Services. However, Visual Studio. NET supports only those basic project types that are extremely common across the developer Communi Ty. Given The wide diversity and disparity of developer needs, Visual Studio. NET (and for that matter, previous versions of V Isual Studio As, expose an extensible architecture, where developers can write their own custom project types and Wiz Ards. This is a excellent feature that allows developers to write canned skeleton code so can be generated automatically, wit Hout has to resort to the infamous "Copy-paste" Anti-pattern. One of the strongest motivations for writing custom wizardsis to write skeleton the code once, and have it automatically customized, generated, and added to further. In this article, we'll explore Visual Studio. NET ' s support for building custom wizards, and discuss how developers can create their own and project templates. Further, we'll build a sample wizard this generates a class that maintains a thread pool holding a specified number of T Hreads. Each of these threads'll call a user specified method via the use of Delegates. All the thread management is handled by the generated code.
Note:this article is based on Visual Studio. NET Beta 2 and Windows 2000.
In this article, we use the words Wizardsand Templatesinterchangeably.
Existing Projects Types and Wizards
The following screen shot shows some of the project templates and wizards this are by Visual Studio. NET by supported Ult.

When a project type and template are chosen, Visual Studio. NET creates a solution and project based on the user ' s selectio N, and generates some files that contain the skeleton code. Some project templates, like the Class LibraryTemplate, generate very simple code so contains one class and a stub for it constructor, while templates such as Visual Studio. NET add-insOr ATL ServerGenerate quite a few files, each containing substantial code. This generated the code are usually stored in a file with placeholders for user input values, such as the Class and project Nam E. When a specific the project type is chosen, Visual Studio. NET invokes a component this reads these canned (also known as T emplated) files, and substitutes the placeholders with the user input values. Next, this component creates the required projects and solutions using the Visual Studio. NET Extensibility Model. Visual Studio. NET looks for specific files in a fixed location that contain information about the available project Templ Ates, and the components that'll be responsible for creating new projects on that based. We'll cover this architecture at the next section.
Visual Studio. NET Project Template Architecture
Visual Studio. NET uses a component based model to support the project templates. Each project template has a corresponding component this handles requests for the given. A single component can handle requests for multiple templates as. Visual Studio. NET uses two types of files, are used to identify the project templates, and the components that handle Requests for this project templates. The "identified by a. vsz extension" Contains information about the component, and any custom parameters that T He component handling the project template might need. The second file (identified by a. vsdir extension) contains information about the description of the project type, and dis Play Properties in the New Projectdialog box. Let us now explain this two files in detail.
    • VSZ file: This file contains information for a single project template. The name of the file corresponds to a entry in the. vsdir files (explained below), and the contents of the file contains The ProgId or the ClassId of the component that would be invoked when this specific project template is chosen. Further, this file can hold custom parameters that would be passed to the component, when invoked. These parameters are typically used when a single component handles multiple template. The Visual Studio. NET IDE is responsible for parsing this file and passing the parameters to the handler.

A Sample. vsz file that handles C # Console Projectsis shown below. The "the" the ' used for versioning, the Wizard ' used to "to" the ProgId of the component that would handle req Uests for C # console projects, and the multiple Param tags contain information that'll be passed to the Vswizard.vswizar Dengine component. This is the component handles multiple templates, so parameters specify the specific template (console project) and The selected language (C #).
VsWizard 7.0
param= "wizard_name = Csharpconsolewiz"
param= "WIZARD_UI = FALSE"
param= "Project_type = CSPROJ"
All components this act as handlers for project templates need to support the IDTWizard interface from the EnvDTE E. This wizard contains a single method, Execute, which are called when the template is invoked. Visual Studio. NET passes the base DTE object (used to access the entire Visual Studio. NET object model, please refer to The links section for articles so cover this), a parameter list containing information such as the name and path of the Project as specified by the user, and another parameter list which contains the custom parameters from the. vsz files as Sh Own above. This information was sufficient for the component to process the template request, and since the method has access to the R Oot DTE object, the component can create solution and projects by invoking methods on this object.
    • VSDIR file: This file contains information about the individual. vsz files explained. This is information relates mainly to the "template in" New Project dialog box displayed by Visual Studio. NET. This display information includes a description for the template which is displayed when the template is selected, Informat Ion about the icon that'll be displayed in the New Project dialog box, and flags this control certain elements On this dialog box. A. vsdir file typically contains a single line entry for multiple. vsz files. The different fields are separated by a "|" character, and the different lines-are by a-new line separated. Multiple. vsdir files are supported by Visual Studio. NET.

A Sample. vsdir file containing two entries is shown below.
csharpexe.vsz| {fae04ec1-301f-11d3-bf4b-00c04f79efbc}| #2318 |10| #2319 |
{fae04ec1-301f-11d3-bf4b-00c04f79efbc}|4554| | WindowsApplication
csharpwebapp.vsz| {fae04ec1-301f-11d3-bf4b-00c04f79efbc}| #2326 |40| #2327 |
{fae04ec1-301f-11d3-bf4b-00c04f79efbc}|4551|1| Webapplication1|web
Some of the main fields in this file are described below. For a complete description of those fields and their relative orders, please refer to the "Links section" at the "this" Article.
    • Relpathname:this field contains the path for the. vsz file.
    • Sortpriority:this field defines the order in which the different templates would be displayed in the New Project dialog box.
    • Description:this field contains a descriptive string that displays information about the specific template.
    • Dllpath:this field points to the DLL of that contains a icon that'll be displayed for this template in the New projec T dialog box.

When the New Projectdialog box is invoked, Visual Studio. NET reads All-VSDir and the. vsz files to display the available project Templat Es. For the C # project type, this are read from the Microsoft Visual\vc#\csharpprojectsfolder as shown below. This folder contains all of the files that represent the C # templates that are available to the New Projectdialog box. Later in the article, where we create our Custom wizard, we'll have to copy of the. vsz and. vsdir files into this folder.

Related Article

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: 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.