Create a project template with a wizard in Visual Studio

Source: Internet
Author: User
For test development, the number of new projects is much higher than that of full-time developers. Every time a test project is created, a lot of attributes need to be set routinely. Code Is time-consuming. Therefore, we plan to create a project template to achieve our goal. For example, when creating a project in visual stuido, you can directly select the created "gtest Project", a wizard dialog box will pop up, and then set some properties, A gtest project that can be used directly is created.
After sorting out, we need two main functions:
1. Project template)
2. Project Wizard)

Vistual studio has a very convenient function, that is, you can directly export a project as a template (menu "file-export template"), the exported file is a zip compressed file, put it in my Documents \ Visual Studio 2008 \ Templates \ projecttemplates. To install Program To decompress the file, add a. vscontent file, compress the file, and change the suffix of the compressed file to. VSI.
The. vscontent file is as follows: < Vscontent Xmlns = "Http://schemas.microsoft.com/developer/vscontent/2005" >
< Content >
< Filename > Myprojecttemplate.zip </ Filename >
< Displayname > Sample project template </ Displayname >
< Description > A project template created for this example. </ Description >
< Filecontenttype > Vstemplate </ Filecontenttype >
< Contentversion > 1.0 </ Contentversion >
< Attributes >
< Attribute Name = "Projecttype" Value = "Visual Basic" />
< Attribute Name = "Projectsubtype" Value = "" />
< Attribute Name = "Templatetype" Value = "Project" />
</ Attributes >
</ Content >
</ Vscontent >

In this way, the project template to be implemented in the first step is very easy to implement. The next step is to implement a setup wizard. To implement a setup wizard, you need to do the following:
1. Create a new class lirary wizard project.
2. Add. Net references: "Microsoft. visualstudio. templatewizardinterface" and "envdte"
3. Create a Windows form (Setup Wizard) and add some widgets you want. And ensure that the Set attributes can be obtained externally.
4. Create a new class to implement the iwizard interface. Mainly implements the runstarted method. In the runstarted method, create the previous windows form, obtain the set attributes, and add them to replacementsdictionary. For example: replacementsdictionary. Add ("$ myname $", myname );
5. Create a project as a template. In this project, you can use "$ myname $" to replace the previously set myname attribute.
6. Install the DLL compiled by the wizard project to the Global Assembly Cache. Generally, gacutil-I XXX. dll is used.
7. Export the previously created template project, decompress the ZIP file, open the. vstemplate file, and add references to the wizard dll: < Wizardextension >
< Assembly > Mytemplatewizardlib, version = 1.0.0.0, culture = neutral, publickeytoken = 345b65148ade810f, processorarchitecture = msil </ Assembly >
< Fullclassname > Mytemplatewizardlib. mywizardlib </ Fullclassname >
</ Wizardextension >

8. compress the file and place the ZIP file in my Documents \ Visual Studio 2008 \ Templates \ projecttemplates.

In this way, a Project template with the setup wizard is created. For example, you can select the Lib reference or DLL reference to be added in the Wizard. Then, I automatically set the reference to the new project. If it is a gtest project, I will automatically write a few regular statements in the Main Function in the template. In short, you can customize almost all the content that I need in advance to improve code writing efficiency.

the method recorded above is general and may be obscure if we haven't touched it before. The following address provides a video teaching, it may be easier to understand:
http://msdn.microsoft.com/en-us/vstudio/bb669054.aspx
more information:
How: use wizards with project templates
How: package community components to use the Visual Studio content installer
Visual Studio templates
create reusable project and item templates for your development team
Create A Visual Studio Project template-a no

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