Create an item template-template parameters

Source: Internet
Author: User

All templates Support Parameter replacement during template instantiation to replace key parameters, such as class names and namespaces. When you click OK in the "New Project" and "Add new project" dialog boxes, these parameters will be replaced by the template wizard running in the background.

Declare and enable template parameters

Template parameters start with $Parameter$ Format. For example:

  • $ Safeprojectname $

  • $ Safeclassname $

  • $ Guid1 $

  • $ Guid5 $

Enable parameter substitution in the template
  1. In the. vstemplate file of the template, locateProjectitemElement.

  2. SetProjectitemElementReplaceparametersSet propertyTrue.

  3. In the code file of the project item, the proper position in the Code includes parameters. For example, the following parameter specifies the security project name used for the namespace in the file:

    Copy code

    namespace $safeprojectname$

Reserved template parameters

The following table lists the reserved template parameters available for all templates.

Note:

The template parameters are case sensitive.

Parameters Description

Clrversion

The current version of the Common Language Runtime Library (CLR.

Guid [1-10]

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

Itemname

The name provided by the user in the Add new project dialog box.

Machinename

The name of the current computer (for example, computer01 ).

Projectname

The name provided by the user in the new project dialog box.

Registeredorganization

The registry key value in HKLM \ Software \ Microsoft \ Windows NT \ CurrentVersion \ registeredorganization.

Rootnamespace

The root namespace of the current project. This parameter is used to replace the namespace in the items added to the forward project.

Safeitemname

The name provided by the user in the "Add new item" dialog box. All unsafe characters and spaces are removed from the name.

Safeprojectname

The name provided by the user in the "New Project" dialog box. All unsafe characters and spaces are removed from the name.

Time

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

Userdomain

The current user domain.

Username

The current user name.

Year

The current year in yyyy format.

Custom template parameters

In addition to the reserved template parameters that are automatically used during parameter replacement, you can also specify your own template parameters and values. For more information, see How to: pass custom parameters to a template.

Example: Replace the file name

You can useTargetfilenameThe property parameter specifies the variable file name for the project item. For example, you can specify the. exe file to use$ Projectname $The specified project name is used as the file name.

Copy code
<TemplateContent><ProjectItemReplaceParameters="true"TargetFileName="$projectname$.exe">File1.exe</ProjectItem>...</TemplateContent>
Example: Use the project name as the namespace name

To use the project name in the namespace of the Visual C # class file class1.cs, use the following syntax:

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

In the. vstemplate file of the Project template, include the following XML When referencing the class1.cs file:

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

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.