简单型的修改类似该路径下的模板文件即可(vs版本或安装路径不同路径可能不同)

C#:

模板参数参考https://msdn.microsoft.com/zh-cn/library/eehb4faa.aspx

<path>\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplates[Cache]\CSharp\Code\2052\Class\Class.cs

例如添加如下内容

/**************************************************************
* Filename: $safeitemrootname$.cs
* Copyright: $registeredorganization$ Co., Ltd.
*
* Description: $safeitemrootname$ ClassFile.
*
* @author: wjshan0808
* @version $time$ @Reviser Initial Version
**************************************************************/

$time$参数的值太长,不合适,如果有$date$最好,可惜默认的没有,那就来添加一个.

步骤:

1.创建强命名程序集

using System;
using System.Collections.Generic;
//添加程序集引用
// Microsoft.VisualStudio.TemplateWizardInterface.dll
// EnvDTE.dll
//
using Microsoft.VisualStudio.TemplateWizard;
using EnvDTE; namespace CustomParameter
{
//IWizard 接口说明
//https://msdn.microsoft.com/zh-cn/library/microsoft.visualstudio.templatewizard.iwizard(v=vs.80).aspx public class CustomParameters : IWizard
{
public void RunFinished()
{
//throw new NotImplementedException();
} public void RunStarted(object automationObject, System.Collections.Generic.Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
try
{
//添加自定义模板参数 Date
string key = "$Date$";
if (replacementsDictionary.ContainsKey(key))
replacementsDictionary.Remove(key);
replacementsDictionary.Add(key, System.DateTime.Now.ToString("MM/dd/yyyy"));
//可以扩展一个修订者
//string extendKey = "Reviser";
//if (replacementsDictionary.ContainsKey(extendKey))
// replacementsDictionary.Remove(extendKey);
//replacementsDictionary.Add(extendKey, "[弹窗/读文件/...]获取信息");
}
catch (Exception ex)
{ }
}
// This method is only called for item templates,
// not for project templates.
public bool ShouldAddProjectItem(string filePath)
{
return true;
} public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem)
{
//throw new NotImplementedException();
} public void ProjectFinishedGenerating(EnvDTE.Project project)
{
//throw new NotImplementedException();
} public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)
{
//throw new NotImplementedException();
}
}
}

可以用sn工具生成.snk文件,也可以左键项目属性->签名创建.snk文件。

项目文件AssemblyInfo.cs中添加snk文件

[assembly: AssemblyKeyFile("CustomParameter.snk")]

/keyfile:  https://msdn.microsoft.com/zh-cn/library/wb84w704.aspx

此操作会出现 <...使用命令行选项“/keyfile”或适当的项目设置代替“AssemblyKeyFile”...>警告,消除警告重新回到属性签名选择生成的snk即可。

使用开发人员命令提示工具

提取公钥到CustomParameter.psnk

>sn -p CustomParameter.snk CustomParameter.psnk

查看公钥信息

>sn -tp CustomParameter.psnk

2.部署到GAC(global assembly cache)

使用管理员身份运行开发人员命令提示工具然后使用GACUtil工具部署程序集

>GACUtil /i CustomParameter.dll

成功标记:程序集已成功添加到缓存中。

程序集卸载(如果代码更新出错什么的..!)

>gacutil /u CustomParameter,Version=1.0.0.0,Culture=Neutral,PublicKeyToken=1d6512175a2e39a6

重新安装

>GACUtil /i CustomParameter.dll /f

3.查看程序集信息

>gacutil /l CustomParameter
全局程序集缓存包含下列程序集:
CustomParameter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1d6512175a2e39a6, processorArchitecture=MSIL 项目数 =

4.修改模板文件

<path>\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplates[Cache]\CSharp\Code\\Class\Class.vstemplate

参考:https://msdn.microsoft.com/zh-cn/library/ms185301.aspx

添加程序集块

  <WizardExtension>
<Assembly>CustomParameter, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=1d6512175a2e39a6</Assembly>
<FullClassName>CustomParameter.CustomParameters</FullClassName>
</WizardExtension>

到此看看效果

/**************************************************************
* Filename: Class2.cs
* Copyright: Microsoft Co., Ltd.
*
* Description: Class2 ClassFile.
*
* @author: wjshan0808
* @version 09/01/2016 @Reviser Initial Version
**************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication1
{
class Class2
{
}
}

@Reviser修订者值可以加一个自定义参数值

  </TemplateContent>
。。。
<CustomParameters>
<CustomParameter Name="@Reviser" Value="wjshan0808"/>
</CustomParameters>
</TemplateContent>

$registeredorganization$值是微软的。

读的是HKLM\Software\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization项值,我想改,不敢改,怕出错。

更可取的方式是自定义一个。

C++:

vs低版本可以用宏,我的2010看网上的教程用宏结果没效果,因为不懂VB,也不懂宏,不知道怎么解决了。先把代码记下。

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics Public Module Comments
Public Sub FileSign()
Dim DocSel As EnvDTE.TextSelection
DocSel = DTE.ActiveDocument.Selection '活动点移到文件开头
DTE.ActiveDocument.Selection.StartOfDocument() DocSel.Text = "/**************************************************************"
DocSel.NewLine()
DocSel.Text = " * Filename:" + "\t" + DTE.ActiveDocument.Name
DocSel.NewLine()
DocSel.Text = " * Copyright:" + "\t" + "XX Co., Ltd."
DocSel.NewLine()
DocSel.Text = " * Description:" + "\t" + ""
DocSel.NewLine()
DocSel.Text = " * @author:" + "\t" + "wjshan0808"
DocSel.NewLine()
DocSel.Text = " * @version" + "\t" + "" + Date.Today.ToString("MM/dd/yyyy") + " wjshan0808 Initial Version"
DocSel.NewLine()
DocSel.Text = " *@"
DocSel.Text = " **************************************************************/"
DocSel.NewLine()
DocSel.NewLine()
End Sub Public Sub FuncSign()
Dim DocSel As EnvDTE.TextSelection
DocSel = DTE.ActiveDocument.Selection
DocSel.NewLine()
DocSel.Text = "/**************************************************************"
DocSel.NewLine()
DocSel.Text = " * Description."
DocSel.NewLine()
DocSel.Text = " * "
DocSel.NewLine()
DocSel.Text = " * @param -[in,out] Type name: [commet]"
DocSel.NewLine()
DocSel.Text = " * @return Value"
DocSel.NewLine()
DocSel.Text = " * "
DocSel.NewLine()
DocSel.Text = " * @version" + "\t" + Date.Today.ToString("MM/dd/yyyy") + " wjshan0808 Initial Version"
DocSel.NewLine()
DocSel.Text = " **************************************************************/"
End Sub End Module

最终用了个折中的方式,修改了新建C++.h.cpp文件,添加了个非智能的版本信息注释,再用工具做方法的注释

<path>\Microsoft Visual Studio 10.0\VC\vcprojectitems\hfile.h
<path>\Microsoft Visual Studio 10.0\VC\vcprojectitems\newc++file.cpp

这样的

/**************************************************************
* Filename: @OutputName.cpp
* Copyright: @Company Co., Ltd.
*
* Description: 模板测试源文件.
*
* @author: @Author
* @version @MM/@dd/@yyyy @Reviser Initial Version
**************************************************************/ #pragma once #include <iostream>
#include <cmath>
#include <cstdlib> using namespace std; className::className()
{ } className::~className()
{ } /**
* 测试方法.
*
* @param -[in,out] char* pName: [测试参数]
*
* @return 0.
*
* @version 09/01/2016 @reviser Initial Version
*/
long className::Test(char* pName)
{ }
/**************************************************************
* Filename: @OutputName.h
* Copyright: @Company Co., Ltd.
*
* Description: 模板测试头文件.
*
* @author: @Author
* @version @MM/@dd/@yyyy @Reviser Initial Version
**************************************************************/ #pragma once #include <stdio.h> class className //: public baseClass
{
//private:
int m_Test; public:
className();
virtual ~className(); public:
long Test(char* pName); protected:
bool m_Ok; };

用第三方工具推荐一个收费的http://www.atomineerutils.com/download.php,试了一下挺好用。可惜收费。

项目文档模板代码 http://pan.baidu.com/s/1eSC1a0a

C#,C++修改vs文件模板,添加自定义代码版权版本信息的更多相关文章

  1. vs2017创建文件模板(自动添加创建信息:创建者,创建日期等信息)

    很多小伙伴在创建新的类的时候都要都要手动写类的注释,如作者名称.创建日期.版本等等,当有几个类的时候还可以手动写写,但有几十个或者更多的类的时候就麻烦了,所以我们可以设定Visual Studio 2 ...

  2. 根据.MDF文件查看 SQL数据库的版本信息

    http://www.cnblogs.com/eason-chan/p/3695753.html?utm_source=tuicool 手上有 经理带来的一个教学管理系统,由于不知道开发环境,在向SQ ...

  3. 基本上,把switch,用设计模式代替,肯定是bug和过度设计。想想,本来修改一个文件几行代码可以解决的问题,变成修改3-6个类才能实现一样的功能。不是傻是什么?

    那些迷信设计模式的人,来修改一下这个方法吧.看看你最终的代码膨胀为几倍... public virtual PasswordChangeResult ChangePassword(ChangePass ...

  4. 如何修改win7文件夹的显示方式为详细信息

    1.首先对着空白处,鼠标右键单击,然后点击“排列方式” 选一个 还有 你还可以点击“查看” 选择图标大小.详细信息.平铺.列表 等2.点击我的电脑左上角的 组织 按钮 随后选择“文件夹和搜索选项” 再 ...

  5. pycharm 修改新建文件时的头部模板(默认为__author__='...')

    pycharm 修改新建文件时的头部模板 默认为__author__='...'    [省略号是默认你的计算机名] 修改这个作者名的步骤: 依次点击:File->Settings->Ed ...

  6. 修改servlet的模板代码

    实际开发中,这些生成的代码和注释一般我们都用不到的,每次都要手工删除这些注释和代码,很麻烦.下面以MyEclipse 2014(其实版本通用的,都可以修改)为例进行说明如何修改Servlet的模板代码 ...

  7. pycharm 修改新建文件时的头部模板

    pycharm 修改新建文件时的头部模板 默认为__author__='...' [省略号是默认你的计算机名] 修改这个作者名的步骤: 依次点击:File->Settings->Edito ...

  8. 按模板批量修改Excel文件内容

    Sub 按模板修改Excel文件() Dim MoBanWorkBook As Workbook Set MoBanWorkBook = Application.ActiveWorkbook Dim ...

  9. java实现批量修改指定文件夹下所有后缀名的文件为另外后缀名的代码

    java实现批量修改指定文件夹下所有后缀名的文件为另外后缀名的代码 作者:Vashon package com.ywx.batchrename; import java.io.File; import ...

随机推荐

  1. Android自动化测试 - Robotium之re-sign.jar重签名后安装失败提示Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]解决方案

    问题:在用re-sign.jar重签名apk文件后,显示重签名成功,但在实际安装过程中确提示:Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES] 原因:网上查 ...

  2. VR寒冬AR暖春,以色列AR公司再获3000万美元融资

    据统计,2015年国内至少有近70家VR公司获得天使或者A轮投资,不过狂欢并没有持续太久.2016年即将结束,资本寒冬和VR头盔的出货远不如预期,让投资者放慢了步伐,不过AR领域的热度依然不减.近日, ...

  3. 使用JQuery UI selectmenu, onchange事件失效

    今天, 在用jQuery UI的一套东西是发现<select class="dropmenu" onchange="do();"></sele ...

  4. [LintCode] Maximum Depth of Binary Tree 二叉树的最大深度

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  5. css3新特性

    1.css3选择器   我们所定义的 CSS 属性之所以能应用到相应的节点上,就是因为 CSS 选择器模式.参考下述代码: Body > .mainTabContainer div > s ...

  6. 在线OJ实用技巧(转载)

    1.一般用C语言节约空间,要用C++库函数或STL时才用C++; cout.cin和printf.scanf最好不要混用. 2.有时候int型不够用,可以用long long或__int64型(两个下 ...

  7. CI 资源文件加入模板

    CI  资源文件加入模板: (资源文件:图片,css,js ,业务文件csv,txt.....) 1.引入url辅助函数库   helper 2.使用base_url函数  生成文件物理硬盘地址 3. ...

  8. python实现之决策树

    一.Predict survival on the Titanic 使用泰坦尼克号上的乘客数据,对乘客是否存活进行预测 1.观察数据集合 可能遇到的问题 训练集和测试集特征值得属性并不重合.连续属性和 ...

  9. hdu 4898 The Revenge of the Princess’ Knight

    传送阵:http://acm.hdu.edu.cn/showproblem.php?pid=4898 题目大意:一个首尾相连的字符串,将其分为k个子串,使得最大的字串最小 将所有子串排序,输出第k小即 ...

  10. sqlserver 性能优化常用方法

    查看被锁表: select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName from sys. ...