您的位置:首页 > 其它

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

2012-03-29 18:11 519 查看
在日常的开发中我们经常需要为我们的类库添加注释和版权等信息,这样我们就需要每次去拷贝粘贴同样的文字,为了减少这种重复性的工作,我们可以把这些信息保存在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会看到如下内容。

1 using System;
2 using System.Collections.Generic;
3 $if$ ($targetframeworkversion$ >= 3.5)using System.Linq;$endif$
4 using System.Web;
5 using System.Web.UI;
6 using System.Web.UI.WebControls;
7
8 namespace $rootnamespace$
9 {
10     public partial class $classname$ : System.Web.UI.Page
11     {
12         protected void Page_Load(object sender, EventArgs e)
13         {
14
15         }
16     }
17 }

复制代码

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

$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$  当前的用户名。

复制代码

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

1 // ===============================================================================
2 // Project Name        :    Weisenz.Core
3 // Project Description :
4 // ===============================================================================
5 // Class Name          :    HttpModule
6 // Class Version       :    v1.0.0.0
7 // Class Description   :
8 // Author              :    Charles
9 // Create Time         :    2012/3/29 13:19:28
10 // Update Time         :    2012/3/29 13:19:28
11 // ===============================================================================
12 // Copyright © Weisenz 2012 . All rights reserved.
13 // ===============================================================================

复制代码

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

1 // ===============================================================================
2 // Project Name        :    $rootnamespace$
3 // Project Description :
4 // ===============================================================================
5 // Class Name          :    $safeitemrootname$
6 // Class Version       :    v1.0.0.0
7 // Class Description   :
8 // Author              :    $username$
9 // Create Time         :    $time$
10 // Update Time         :    $time$
11 // ===============================================================================
12 // Copyright © $machinename$ $year$ . All rights reserved.
13 // ===============================================================================

复制代码

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

看下我的最终成果:

1 // ===============================================================================
2 // Project Name        :    Weisenz.Web
3 // Project Description :
4 // ===============================================================================
5 // Class Name          :    Services
6 // Class Version       :    v1.0.0.0
7 // Class Description   :
8 // Author              :    Charles
9 // Create Time         :    2012/3/29 13:38:53
10 // Update Time         :    2012/3/29 13:38:53
11 // ===============================================================================
12 // Copyright © Weisenz 2012 . All rights reserved.
13 // ===============================================================================
14 using System;
15 using System.Collections.Generic;
16
17 using System.Web;
18 using System.Web.UI;
19 using System.Web.UI.WebControls;
20
21 namespace Weisenz.Web
22 {
23     public partial class Services : System.Web.UI.Page
24     {
25         protected void Page_Load(object sender, EventArgs e)
26         {
27
28         }
29     }
30 }

复制代码

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

Asp.net

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

摘要: 在日常的开发中我们经常需要为我们的类库添加注释和版权等信息,这样我们就需要每次去拷贝粘贴同样的文字,为了减少这种重复性的工作,我们可以把这些信息保存在Visual Studio 2010类库模版文件里。首先找到Visual Studio 2010的安装路径下\Common7\IDE\ItemTemplatesCache\CSharp\目录,如图:里面有好多目录,Windows Forms是开发Windows Forms程序的模版目录,Web是Web项目文件的模版目录,其他的同理。进入Web目录有选择2052目录(2052是中文地区的代号)下,会看到好多带有.zip的目录,比如我要修改web页面阅读全文

posted @ 2012-03-29 14:23 张鸿伟 阅读(793) | 评论 (11) 编辑

jquery左侧导航网页菜单

摘要: 公司项目需要写一个左侧导航菜单,在网上找了好多源码参考,处理的都很复杂,移植性不是很好,最后根据一个比较不错的修改了一下达到了想要的效果。前端HTML代码:View Code 1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 4 <title>jquery左侧导航网页菜单</ti阅读全文

posted @ 2012-03-28 10:50 张鸿伟 阅读(22) | 评论 (0) 编辑
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: