zoukankan      html  css  js  c++  java
  • Visual Studio自定义模板参数说明

    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, locate the ProjectItem element that corresponds to the item that you want to enable parameter replacement for.

    2. Set the ReplaceParameters attribute of the ProjectItem element to true.

    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.

    NoteNote

    Template parameters are case-sensitive.

     
    ParameterDescription

    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 in the Add New Item dialog box, with all unsafe characters and spaces removed.

    safeprojectname

    The name provided by the user in the New Project dialog 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.

    Custom 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 with the TargetFileName attribute. For example, you could specify that the .exe file use the project name, specified by $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 directives
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    #endregion
    
    namespace $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>

    参考:http://msdn.microsoft.com/en-us/library/eehb4faa(v=vs.80).aspx

    作者:Olar Tan
    出处:http://www.cnblogs.com/olartan
    ♪:没有做不到的 只有偷懒而错过的 ♪

  • 相关阅读:
    与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误
    ExecuteNonQuery()>0
    Newtonsoft.Json 你必须知道的一些用法
    API Test WebApiTestClient工具安装及使用
    vb 无效的属性值,运行时错误380
    洛谷P4296 [AHOI2007] 密码箱——题解
    pip install mysql-python 安装错误解决方案,whl安装,exe 安装
    安装包模块出现的下载源问题解决:An HTTPS request has been made /Could not find a version that satisfies the requirement pyopenssl
    fast_admin 添加产品信息后台管理sql
    kafka 记录(转)
  • 原文地址:https://www.cnblogs.com/olartan/p/2606898.html
Copyright © 2011-2022 走看看