Visual Studio custom template (3)

Source: Internet
Author: User

Continue with Visual Studio custom templates (2). To implement dynamic custom template parameters, go back to the vstemplate file. In this file, we can configure our own wizard extension wizardextension, with wizardextension, you can add customCode.

First, we implement a simple custom wizard,

  Namespace  Mytemplate
{
Using System;
Using System. Collections. Generic;
Using Microsoft. visualstudio. templatewizard;

Public Class Mywizard: iwizard
{
/// <Summary>
/// Runs custom wizard logic before opening an item in the template.
/// </Summary>
/// <Param name = "projectitem"> The project item that will be opened. </Param>
Public Void Beforeopeningfile (envdte. projectitem)
{
}

/// <Summary>
/// Runs custom wizard logic when a project has finished generating.
/// </Summary>
/// <Param name = "project"> The project that finished generating. </Param>
Public Void Projectfinishedgenerating (envdte. Project)
{
}

/// <Summary>
/// Runs custom wizard logic when a project item has finished generating.
/// </Summary>
/// <Param name = "projectitem"> The project item that finished generating. </Param>
Public Void Projectitemfinishedgenerating (envdte. projectitem)
{
}

/// <Summary>
/// Runs custom wizard logic when the wizard has completed all tasks.
/// </Summary>
Public Void Runfinished ()
{
}

/// <Summary>
/// Runs the started.
/// </Summary>
/// <Param name = "automationobject"> The automation object. </Param>
/// <Param name = "replacementsdictionary"> The replacements dictionary. </Param>
/// <Param name = "runkind"> Kind of the run. </Param>
/// <Param name = "customparameters"> The custom parameters. </Param>
Public Void Runstarted ( Object Automationobject,
Dictionary < String , String > Replacementsdictionary,
Wizardrunkind runkind,
Object [] Customparameters)
{
Replacementsdictionary. Add ( " $ Mydate $ " , Datetime. Now. tostring ( " Yyyy-mm-dd hh: mm: SS " ));
}

/// <Summary>
/// Indicates whether the specified project item shocould be added to the project.
/// </Summary>
/// <Param name = "filepath"> The path to the project item. </Param>
/// <Returns>
/// True if the project item shocould be added to the project; otherwise, false.
/// </Returns>
Public Bool Shouldaddprojectitem ( String Filepath)
{
Return True ;
}
}
}

For the specific definitions of iwizard methods, refer to msdn. Here, I added a custom template parameter $ mydate $ TO THE runstarted method, whose value is datetime. now. tostring ("yyyy-mm-dd hh: mm: SS"), that is, all $ mydate $ in the template file will be replaced with the specified date string.

The next step is to add the wizard configuration we defined in the vstemplate file. VS has a requirement that all Wizard extensions must be installed in GAC. Therefore, we must name the one we just generated.ProgramSet to install in GAC. First, find the template we generated in 2 in [my documents] \ Visual Studio 2005 \ Templates \ itemtemplates. decompress the template and modify the vstemplate file as follows,

< Vstemplate Version = "2.0.0" Xmlns = "Http://schemas.microsoft.com/developer/vstemplate/2005" Type = "Item" >
...
< Wizardextension >
< Assembly > Mytemplate, version = 1.0.0.0, culture = neutral, publickeytoken = 5ea13aa0d9868d4b </ Assembly >
< Fullclassname >
Mytemplate. mywizard
</ Fullclassname >
</ Wizardextension >
</ Vstemplate >

 
 

Note: The configuration information of the Assembly above should be modified according to the specific strong naming information.

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.