Visual Studio 创建类时自动添加版权说明和作者信息
2013-02-07 13:24
603 查看
写代码时,我们一般需要在Code File的最前面声明版权信息,作者的联系方式等。一些高级的IDE工具提供修改代码模板的功能,这样就能够在创建新代码时自动加上版权信息等。Visual Studio虽然没有提供这样的操作界面,但是我们可以通过手动修改原始代码模板来达到这个目的。
一、首先找到模板目录,例如我安装的Visual Studio 2008在C盘,则对应的模板目录是C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\ 。这个目录包含了所有模板,都是以zip文件存在的。这里举例C#的Class.zip和Interface.zip模板,可以在C:\Program
Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\下找到那两个zip文件。注意路径中的1033表示是英文版,如果是中文版,应该是2052。
二、修改模板。修改模板其实很简单,就是把那两个zip文件解压缩,修改里面的cs文件,然后重新压缩成一样的zip包。比如我修改的Class模板文件如下:
//==============================================================
// Copyright (C) $year$ Jeteam Inc. All rights reserved.
//
// The information contained herein is confidential, proprietary
// to Jeteam Inc. Use of this information by anyone other than
// authorized employees of Jeteam Inc is granted only under a
// written non-disclosure agreement, expressly prescribing the
// scope and manner of such use.
//==============================================================
// Create by Andrew Zhou at $time$.
// Version 1.0
// Andrew Zhou [mailto:fzhou.andrew@gmail.com]
//==============================================================
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ == 3.5)using System.Linq;
$endif$using System.Text;
namespace $rootnamespace$
{
/// <summary>
///
/// </summary>
class $safeitemrootname$
{
}
}
这里面可以用一些参数,下面列出一些:itemname, safeitemname, safeitemrootname, projectname, safeprojectname, rootnamespace, guid[1-10], time, year, username, userdomain, machinename, clrversion, registered-organization, wizarddata 。具体代表的含义大家都可以猜得出来。
三、部署模板。部署模板也很简单,只需要覆盖原来的模板就可以。把自己重新制作的zip包放入到\ItemTemplates\CSharp\Code\1033\下面去覆盖原来的同名zip文件就可以了。
注意:可能完成上边操作后,重新建立一个class的时候,发现VS并没有使用我们定制的模板,这个原因就是一个缓存问题。VS会在C:\Program
Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache\文件夹中去寻找同名的模板文件,所以我们要也把这里改了,注意,这里的.zip结尾的只是一个文件夹,并不是一个压缩文件。
参考内容 http://www.cnblogs.com/andrewzhou/archive/2008/06/04/visual_studio_comment_copyright.html
一、首先找到模板目录,例如我安装的Visual Studio 2008在C盘,则对应的模板目录是C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\ 。这个目录包含了所有模板,都是以zip文件存在的。这里举例C#的Class.zip和Interface.zip模板,可以在C:\Program
Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\下找到那两个zip文件。注意路径中的1033表示是英文版,如果是中文版,应该是2052。
二、修改模板。修改模板其实很简单,就是把那两个zip文件解压缩,修改里面的cs文件,然后重新压缩成一样的zip包。比如我修改的Class模板文件如下:
//==============================================================
// Copyright (C) $year$ Jeteam Inc. All rights reserved.
//
// The information contained herein is confidential, proprietary
// to Jeteam Inc. Use of this information by anyone other than
// authorized employees of Jeteam Inc is granted only under a
// written non-disclosure agreement, expressly prescribing the
// scope and manner of such use.
//==============================================================
// Create by Andrew Zhou at $time$.
// Version 1.0
// Andrew Zhou [mailto:fzhou.andrew@gmail.com]
//==============================================================
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ == 3.5)using System.Linq;
$endif$using System.Text;
namespace $rootnamespace$
{
/// <summary>
///
/// </summary>
class $safeitemrootname$
{
}
}
这里面可以用一些参数,下面列出一些:itemname, safeitemname, safeitemrootname, projectname, safeprojectname, rootnamespace, guid[1-10], time, year, username, userdomain, machinename, clrversion, registered-organization, wizarddata 。具体代表的含义大家都可以猜得出来。
三、部署模板。部署模板也很简单,只需要覆盖原来的模板就可以。把自己重新制作的zip包放入到\ItemTemplates\CSharp\Code\1033\下面去覆盖原来的同名zip文件就可以了。
注意:可能完成上边操作后,重新建立一个class的时候,发现VS并没有使用我们定制的模板,这个原因就是一个缓存问题。VS会在C:\Program
Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache\文件夹中去寻找同名的模板文件,所以我们要也把这里改了,注意,这里的.zip结尾的只是一个文件夹,并不是一个压缩文件。
参考内容 http://www.cnblogs.com/andrewzhou/archive/2008/06/04/visual_studio_comment_copyright.html
相关文章推荐
- Visual Studio 技巧1 - 创建类时自动添加版权说明和作者信息
- idea创建新的类(文件)时,自动添加作者创建时间(文件注释)等信息的设置方法
- Unity添加脚本的时候,自动创建版权信息
- Ecplise创建一个类的时候如何自动添加作者,时间等信息
- Vim中自动在程序起始处添加版权和作者信息
- 在VS2008中自动添加版权和作者信息
- Vim中自动在程序起始处添加版权和作者信息
- Vim中自动在程序起始处添加版权和作者信息
- Visual Studio 2010: 修改默认模板文件信息,添加代码版权信息
- 修改VS类模板自动添加public修饰符和版权注释信息
- VS中为类,函数代码自动添加版权注释信息
- VS中为类,函数代码自动添加版权注释信息
- Eclipse新建类的时候如何自动添加注释(作者,时间的信息
- VS中为类,函数代码自动添加版权注释信息
- 【未试】VS2008 修改模板自动添加版权信息与添加宏注释方法
- Eclipse4.7基础 修改生成的.java文件模板,添加作者信息与创建时间
- 自动添加版权信息
- VS中为类,函数代码自动添加版权注释信息
- 添加客人信息 创建 div 选择姓名 自动把证件号放入了文本框
- Eclipse中创建java类的时候自动设置作者信息和创建时间