zoukankan      html  css  js  c++  java
  • Visual Studio 自动添加头部注释信息

    在日常的开发中我们经常需要为我们的类库添加注释和版权等信息,这样我们就需要每次去拷贝粘贴同样的文字,为了减少这种重复性的工作,我们可以把这些信息保存在 Visual Studio 2010 类库模版文件里。

    首先找到 Visual Studio 2010 的安装路径下 \Common7\IDE\ItemTemplatesCache\CSharp\ 目录,如图:

    里面有好多目录,Windows Forms 是开发 Windows Forms 程序的模版目录,Web 是 Web 项目文件的模版目录,其他的同理。

    进入 Web 目录有选择 2052 目录(2052 是中文地区的代号)下,会看到好多带有 .zip 的目录,比如我要修改 Web 页面的模版,就修改 \WebForm.zip\Default.aspx.cs,打开 Default.aspx.cs 会看到如下内容。

    using System;
    using System.Collections.Generic;
    $if$ ($targetframeworkversion$ >= 3.5)using System.Linq;$endif$
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace $rootnamespace$
    {
        public partial class $classname$ : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
        }
    }

    代码中的 "$" 符号之间的字符是模版的变量,具体变量含义请参照:

    $time$     日期
    
    $year$     年份
    
    $clrversion$    CLR 版本
    
    $GUID$   用于替换项目文件中的项目 GUID 的 GUID。最多可以指定 10 个唯一的 GUID(例如,guid1))。
    
    $itemname$  用户在对话框中提供的名称。
    
    $machinename$    当前的计算机名称(例如,Computer01)。
    
    $projectname$   用户在对话框中提供的名称。
    
    $registeredorganization$   HKLM\Software\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization 中的注册表项值。
    
    $rootnamespace$  当前项目的根命名空间。此参数用于替换正向项目中添加的项中的命名空间。
    
    $safeitemname$  用户在“添加新项”对话框中提供的名称,名称中移除了所有不安全的字符和空格。
    
    $safeprojectname$  用户在“新建项目”对话框中提供的名称,名称中移除了所有不安全的字符和空格。
    
    $time$    以 DD/MM/YYYY 00:00:00 格式表示的当前时间。
    
    $userdomain$  当前的用户域。
    
    $username$  当前的用户名。

    下面是我写注释的格式,那我们就按照这个格式做一个模版。

    // ===============================================================================
    // Project Name        :    Weisenz.Core
    // Project Description :    
    // ===============================================================================
    // Class Name          :    HttpModule
    // Class Version       :    v1.0.0.0
    // Class Description   :    
    // Author              :    Charles
    // Create Time         :    2012/3/29 13:19:28
    // Update Time         :    2012/3/29 13:19:28
    // ===============================================================================
    // Copyright © Weisenz 2012 . All rights reserved.
    // ===============================================================================

    在对应的地方替换成自己需要使用的变量。

    // ===============================================================================
    // Project Name        :    $rootnamespace$
    // Project Description :    
    // ===============================================================================
    // Class Name          :    $safeitemrootname$
    // Class Version       :    v1.0.0.0
    // Class Description   :    
    // Author              :    $username$
    // Create Time         :    $time$
    // Update Time         :    $time$
    // ===============================================================================
    // Copyright © $machinename$ $year$ . All rights reserved.
    // ===============================================================================

    最后把上面的文本添加到 Default.aspx.cs 的最前面就行了。

    下面是我的最终成果:

    // ===============================================================================
    // Project Name        :    Weisenz.Web
    // Project Description :    
    // ===============================================================================
    // Class Name          :    Services
    // Class Version       :    v1.0.0.0
    // Class Description   :    
    // Author              :    Charles
    // Create Time         :    2012/3/29 13:38:53
    // Update Time         :    2012/3/29 13:38:53
    // ===============================================================================
    // Copyright © Weisenz 2012 . All rights reserved.
    // ===============================================================================
    using System;
    using System.Collections.Generic;
    
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Weisenz.Web
    {
        public partial class Services : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
        }
    }

    如果需要修改其他的模版就按照上面的步骤找到对应的文件夹就行了。

  • 相关阅读:
    2021.07.01 学习总结
    2021.06.30 学习总结
    2021.06.29 学习总结
    2021.06.28 学习总结
    ubuntu 安装nginx报错./configure: error: SSL modules require the OpenSSL library
    Docker 启动alpine镜像中可执行程序文件遇到 not found
    docker基于cenots7 制作nginx镜像
    【Linux报错】VM虚拟机的CentOS7系统启动时报Generating /run/initramfs/rdsosreport.txt
    Docker Swarm 集群概念扩展
    Docker Swarm 集群弹性、动态扩缩容
  • 原文地址:https://www.cnblogs.com/weisenz/p/2423326.html
Copyright © 2011-2022 走看看