简单型的修改类似该路径下的模板文件即可(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. 解决Spring的Component-scan和packagesToScan不支持Eclipse RCP问题

    http://www.360doc.com/content/13/0401/13/10825198_275274565.shtml

  2. 关于如何通过定义自己的CameraManager来控制视角

    2016.8.30 发现了这个函数,可以直接获得摄像机的位置和旋转. Controller->GetPlayerViewPoint(CamLoc, CamRot); 最近看了几天PlayerCa ...

  3. 清华学堂 LightHouse

    灯塔(LightHouse) Description As shown in the following figure, If another lighthouse is in gray area, ...

  4. CS: Marshalling and Unmarshalling, Serialization and Unserialization

    Link1: https://en.wikipedia.org/wiki/Marshalling_(computer_science) Quote: " Comparison with se ...

  5. python 自带的ide 不能保存文件

    初学python 用shell写的代码结果不能保存,经查询,原因有人说是因为文件里有中文, import random secret =random.randint(1,100) guess=0 tr ...

  6. Android入门(九):CheckBox多选清单和ScrollView滚动条

    字符串资源文件strings.xml: <resources> <string name="hello">主类main</string> < ...

  7. Mac下抓包

    Wireshark针对UNIX Like系统的GUI发行版界面采用的是X Window(1987年更改X版本到X11).Mac OS X在Mountain Lion之后放弃X11,取而代之的是开源的X ...

  8. ZeroMQ接口函数之 :zmq_z85_decode – 从一个用Z85算法生成的文本中解析出二进制密码

    ZeroMQ 官方地址 :http://api.zeromq.org/4-0:zmq_z85_decode zmq_z85_decode(3)         ØMQ Manual - ØMQ/4.1 ...

  9. 【Alpha】Daily Scrum Meeting总结

    一.项目预期计划和现实进展 项目预期计划 现实进展 登陆 完成 使用菜单 完成 查看自己的信息 完成(额外完成可修改) 完成能用的界面 完成(额外美化) 可以导入导出表格 导入表格完成,导出未完成 教 ...

  10. 常见的HTTP Headers

    协议就是交互双方协商好要遵守的规范,打个不恰当的比方,就好像交谈双方约定要使用的同一种语言.如果我讲英文,你讲中文,大家都相互听不懂,交流那就得嗝屁了. HTTP协议就是需要交互的客户端(通常是浏览器 ...