防止 Visual Studio 为新类添加默认引用和使用 [英] Prevent Visual Studio from adding default references and usings for new classes

查看:22
本文介绍了防止 Visual Studio 为新类添加默认引用和使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我向 Visual Studio (C#) 项目添加新类时,我都会自动获得以下用途:

Whenever I add a new class to a Visual Studio (C#) project, I get the following usings automatically:

  • 使用系统;
  • 使用 System.Collections.Generic;
  • 使用 System.Linq;
  • 使用 System.Text;

此外,如果还没有以下 DLL 引用,则会添加它们:

Additionally, the following DLL references are added if they weren't there already:

  • 系统核心
  • 系统.数据
  • 系统.Xml

我想阻止 VS 这样做(当然使用系统"除外).有没有人知道防止这种情况发生的方法?

I'd like to prevent VS from doing this (except "using System" of course). Does any one know of a way to prevent this from happening?

推荐答案

Marc 和 Brian 都有一个好主意:创建一个新的自定义模板,其中只包含我想要的使用和引用.使用导出模板,这样做真的很简单,我一定会为各种特定项目这样做.

Marc and Brian both have a good idea: create a new custom template that includes only the usings and references I want. With Export Template it's really simple to do so, and I'll be sure to do so for all sorts of specific items.

对于通用的新类(即:您从 VS 中的添加->类..."菜单项中获得的内容),这是我为实现目标所做的工作:

For general-purpose new classes (ie: what you get from the "Add->Class..." menu item in VS), here's what I did to achieve my goal:

  • 找到合适的模板 Zip.在我的系统上,它位于 C:Program FilesMicrosoft Visual Studio 9.0Common7IDEItemTemplatesCSharpCode1033Class.zip
  • 解压压缩文件.这给出了两个文件:Class.cs 和 Class.vstemplate
  • 编辑 Class.cs 以删除不需要的 using 语句.(当我在这里时,我还将默认类访问修饰符更改为public")
  • 编辑 Class.vstemplate 以删除不需要的 元素.
  • 将文件重新压缩到现有的 Class.zip 存档中
  • 用更新的版本替换缓存的模板文件.在我的系统上,这些文件位于 C:Program FilesMicrosoft Visual Studio 9.0Common7IDEItemTemplatesCacheCSharpCode1033Class.zip(一个包含旧 Class.cs 和 Class.vstemplate 的目录).
    • 我尝试简单地删除此目录,希望 VS 从原始"源重建缓存.然而这并没有奏效;我收到一条错误消息,说它在缓存目录中找不到文件.不过,替换缓存文件效果很好.

    现在,每当我添加一个新课程时,我都会得到我想要的.

    Now, whenever I add a new class, I get exactly what I want.

    这篇关于防止 Visual Studio 为新类添加默认引用和使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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