Visual Studio 2010 自动添加头部注释信息

在日常的开发中我们经常需要为我们的类库添加注释和版权等信息,这样我们就需要每次去拷贝粘贴同样的文字,为了减少这种重复性的工作,我们可以把这些信息保存在 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)
        {

        }
    }
}

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值