Visual Studio custom template parameter description

Source: Internet
Author: User
Declaring and Enabling Template Parameters

Template parameters are declared in the format $Parameter$. For example:

  • $ Safeprojectname $

  • $ Safeclassname $

  • $ Guid1 $

  • $ Guid5 $

To enable parameter substitution in templates
  1. In the. vstemplate file of the template, locateProjectItemElement that corresponds to the item that you want to enable parameter replacement.

  2. SetReplaceParametersAttribute ofProjectItemElementTrue.

  3. In the code file for the project item, include parameters in code where appropriate. For example, the following parameter specifies that the safe project name be used for the namespace in a file:

    namespace $safeprojectname$
Reserved Template Parameters

The following table lists the reserved template parameters that can be used by any template.

Note

Template parameters are case-sensitive.

 
Parameter Description

Clrversion

Current version of the common language runtime (CLR ).

GUID [1-10]

A guid used to replace the project GUID in a project file. You can specify up to 10 unique GUIDs (for example,Guid1).

Itemname

The name provided by the user in the Add New Item dialog box.

Machinename

The current computer name (for example, Computer01 ).

Projectname

The name provided by the user in the New Project dialog box.

Registeredorganization

The registry key value from HKLM \ Software \ Microsoft \ Windows NT \ CurrentVersion \ RegisteredOrganization.

Rootnamespace

The root namespace of the current project. This parameter is used to replace the namespace in an item being added to a project.

Safeitemname

The name provided by the user inAdd New ItemDialog box, with all unsafe characters and spaces removed.

Safeprojectname

The name provided by the user inNew ProjectDialog box, with all unsafe characters and spaces removed.

Time

The current time in the format DD/MM/YYYY 00:00:00.

Userdomain

The current user domain.

Username

The current user name.

Year

The current year in the format YYYY.

Paramem Template Parameters

In addition to the reserved template parameters that are automatically used during parameter replacement, you can specify your own template parameters and values. For more information, see How to: Pass Custom Parameters to Templates.

Example: Replacing Files Names

You can specify variable file names for project items using a parameter withTargetFileNameAttribute. For example, you cocould specify that the. exe file use the project name, specified$ Projectname $, As the file name.

<TemplateContent>    <ProjectItem        ReplaceParameters="true"        TargetFileName="$projectname$.exe">            File1.exe    </ProjectItem>      ...</TemplateContent>
Example: Using the Project Name for the Namespace Name

To use the project name for the namespace in a Visual C # class file, Class1.cs, use the following syntax:

#region Using directivesusing System;using System.Collections.Generic;using System.Text;#endregionnamespace $safeprojectname${    public class Class1        {            public Class1()                {                }         }}

In the. vstemplate file for the project template, include the following XML when referencing the file Class1.cs:

<TemplateContent> <ProjectItem ReplaceParameters = "true"> Class1.cs </ProjectItem>... </TemplateContent>

Reference: http://msdn.microsoft.com/en-us/library/eehb4faa (v = vs.80). aspx
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.