简单型的修改类似该路径下的模板文件即可(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. Nginx二级域名及多Server反向代理配置

    Nginx强大的正则表达式支持,可以使server_name的配置变得很灵活,如果你要做多用户博客,那么每个用户拥有自己的二级域名也就很容易实现了. 注:nginx反向代理同一ip多个域名,给head ...

  2. 关于TFS地址改变后,项目迁移的问题。

    经常遇到TFS的服务器地址改变,以至于项目全部不能用,如果全部重新打开,然后重新映射,是件很费时.费事的事.但其实是有简单方法的. 找到解决方法文件,即SLN文件. 用记事本打开,找到SccTeamF ...

  3. C#基础:值类型、引用类型与ref关键字

    在C#中,ref的意思是按引用传递.可以参考C++: int a = 10, b = 20; void swap(int x, int y) { int temp = x; x = y; y = te ...

  4. BC一周年练习赛

    Souvenir  Accepts: 901  Submissions: 2743  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 262 ...

  5. CentOS 7部署Node.js+MongoDB:在VPS上从安装到Hello world

    写好代码,花钱买了VPS,看着Charges一直上涨却无从下手?记一位新手司机从购买VPS到成功访问的过程 0.购买VPS 首先,选择VPS提供商,部署一个新的服务器(Deploy New Serve ...

  6. 10.this关键字

    ①在类的方法定义中使用的this关键字代表使用该方法的对 象的引用 ②当必须指出当前使用方法的对象是谁时要使用this ③有时使用this处理方法中成员变量和参数重名的情况 ④this可以看做是一个变 ...

  7. 【noip 2004】 合并果子

    noip2016结束后的第一份代码--优先队列的练习 合并果子 原题在这里 #include <iostream> #include <queue> #include < ...

  8. 微信分享JS函数(原创)[已失效]

    //微信内置浏览器分享事件 //来自:http://www.cnblogs.com/cielwater //分享朋友圈事件 //UpdateWeixinJSBridge(CircleModel[Jso ...

  9. php变量和数组大小限制

    前言:shopnc在默认拼接sql的时候会带上limit 1000 那么问题就来了,如果在使用系统的封装的方法,但是如果你没有带上->limit(false)就完蛋了 那么问题来了,在判断时候, ...

  10. asp.net identity 2.2.0 在WebForm下的角色启用和基本使用(四)

    有网友问及权限的问题,其实我觉得没什么改进. 主目录下的web.config基本不用改.要说要改的也就只有数据库连接了. <authentication mode="None" ...