如何为新的 C# 类/接口编辑 Visual Studio 模板? [英] How do I edit the Visual Studio templates for new C# class/interface?

查看:25
本文介绍了如何为新的 C# 类/接口编辑 Visual Studio 模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我在 Visual Studio 中创建的几乎每个 C# 文件中都删除了以下导入语句:

I find myself removing the following import statements in nearly every C# file I create in Visual Studio:

using System.Collections.Generic;
using System.Linq;
using System.Text;

当然,使用 Resharper 很容易做到这一点,但我真的不应该这样做.

Of course its really easy to do this with Resharper, but I really should not have to.

VS 目录中的某处一定有一些模板(类、接口),我可以从中删除违规行.我在哪里可以找到这些文件?有没有更好的方法来控制默认导入列表?

There must be a few template (class, interface) somewhere in the VS directory, from which I can remove the offending lines. Where do I find these files? Is there a better way to control the default import list?

推荐答案

2017 至 2019(当前)

Visual Studio 2017 将目录位置更改为使用发布年份而不是其内部版本号,另外还取决于您的版本(专业版/企业版/等):

2017 through 2019 (current)

Visual Studio 2017 changed the directory location to use release year instead of its internal version number, and is additionally dependent on your edition (Professional/Enterprise/etc.):

%ProgramFiles(x86)%Microsoft Visual Studio Common7IDEItemTemplatesCSharpCode1033Class.cs

<头>
版本绝对路径
2019社区%ProgramFiles(x86)%Microsoft Visual Studio 2019CommunityCommon7IDEItemTemplatesCSharpCode1033Class.cs
企业%ProgramFiles(x86)%Microsoft Visual Studio 2019EnterpriseCommon7IDEItemTemplatesCSharpCode1033Class.cs
专业%ProgramFiles(x86)%Microsoft Visual Studio 2019ProfessionalCommon7IDEItemTemplatesCSharpCode1033Class.cs
2017社区%ProgramFiles(x86)%Microsoft Visual Studio 2017CommunityCommon7IDEItemTemplatesCSharpCode1033Class.cs
企业%ProgramFiles(x86)%Microsoft Visual Studio 2017EnterpriseCommon7IDEItemTemplatesCSharpCode1033Class.cs
专业%ProgramFiles(x86)%Microsoft Visual Studio 2017ProfessionalCommon7IDEItemTemplatesCSharpCode1033Class.cs

2012 年至 2015 年

从 VS 2012 开始,模板未压缩,因此您可以直接编辑每个适用文件夹中的每个 .cs 模板.

2012 through 2015

Starting with VS 2012, the templates are not zipped, so you can edit each .cs template in each applicable folder directly.

%ProgramFiles(x86)%Microsoft Visual Studio Common7IDEItemTemplatesCSharpCode1033Class.cs

<头>
版本绝对路径
201514.0%ProgramFiles(x86)%Microsoft Visual Studio 14.0Common7IDEItemTemplatesCSharpCode1033Class.cs
201312.0%ProgramFiles(x86)%Microsoft Visual Studio 12.0Common7IDEItemTemplatesCSharpCode1033Class.cs
201211.0%ProgramFiles(x86)%Microsoft Visual Studio 11.0Common7IDEItemTemplatesCSharp1033Class.cs

2010 年及之前

解压、编辑和重新压缩 ZIP 文件.路径是类模板的,但接口模板在同一个文件夹中.

2010 and older

Extract, edit and recompress the ZIP file. Paths are for the class template, but interface templates are in the same folder.

您可能希望在每个文件中编辑 VS 模板文件,以消除它们不会自动添加对程序集 System、System.Data 和/或 System.Xml 的引用这一事实.

You may want to edit the VS template file in each to remove the fact that they don't automatically add references to the assemblies System, System.Data and/or System.Xml.

%ProgramFiles(x86)%Microsoft Visual Studio Common7IDEItemTemplatesCSharpCode1033Class.zip

<头>
版本绝对路径
201010.0%ProgramFiles(x86)%Microsoft Visual Studio 10.0Common7IDEItemTemplatesCSharpCode1033Class.zip
20089.0%ProgramFiles(x86)%Microsoft Visual Studio 9.0Common7IDEItemTemplatesCSharpCode1033Class.zip
20058%ProgramFiles(x86)%Microsoft Visual Studio 8Common7IDEItemTemplatesCSharp1033Class.zip

注释

速成版

在 Express Editions 中,您必须在 IDE 文件夹内的子目录 WDExpress 中进行搜索,例如对于 VS 2015 Express:

Notes

Express Editions

In Express Editions you will have to search in the subdirectory WDExpress inside the IDE folder, so e.g. for VS 2015 Express:

%ProgramFiles(x86)%Microsoft Visual Studio 14.0Common7IDEWDExpressItemTemplatesCSharpCode1033ClassClass.cs

其他语言

如果您不使用英文版的 Visual Studio,文件夹 1033 可能不存在,而是代表您的语言的不同数字.例如,在德语安装中为 1031.

Other Languages

If you don't use the English version of Visual Studio, the folder 1033 may not exist, but a different number representing your language. For example it is 1031 in a German installation.

这篇关于如何为新的 C# 类/接口编辑 Visual Studio 模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆