Visual studio 创建文件时自动添加备注

时间:2023-03-08 23:52:37
Visual studio 创建文件时自动添加备注

Visual studio 创建文件时自动添加备注

描述

要求每回添加一个类,普通类或单元测试类文件头自动添加备注, 比如:Copyright, FileName, Author and so on.

普通类文件

操作步骤:

1. 找出Class.cs, 存放位置:C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class。

2. 编辑Class.cs文件, 添加上文件备注(绿色部分)。

/*===============================================================================================

 Copyright© $year$ xxx Ltd. All rights reserved.

 File     : $safeitemname$.cs
Author : xxx xxx
Created : $time$
Summary : ===============================================================================================*/
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $rootnamespace$
{
class $safeitemrootname$
{
}
}

单元测试类文件(此处用的是NUnit测试类)

操作步骤:

1. 找到 UnitTest.cs, 存放位置:C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplates\CSharp\Test\1033\BasicUnitTest

2. 编辑UnitTest.cs文件, 添加上文件备注(绿色部分), [TestFixture] and [Test]。

/*===============================================================================================

 Copyright© $year$ xxx Ltd. All rights reserved.

 File     : $safeitemname$.cs
Author : xxx xxx
Created : $time$
Summary : ===============================================================================================*/ using System;
using NUnit.Framework; namespace $rootnamespace$
{
[TestFixture]
public class $safeitemname$
{
[Test]
public void TestMethod1()
{
}
}
}