Whenever I add a new class to a Visual Studio (C#) project, I get the following usings automatically:
每当我向Visual Studio(C#)项目添加一个新类时,我都会自动获得以下用法:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
Additionally, the following DLL references are added if they weren't there already:
此外,如果它们不存在,则添加以下DLL引用:
- System.Core
- System.Data
- System.Xml
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?
我想阻止VS这样做(当然除了“使用系统”)。有没有人知道防止这种情况发生的方法?
3 个解决方案
#1
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.
Marc和Brian都有一个好主意:创建一个新的自定义模板,其中仅包含我想要的使用和引用。使用导出模板,这样做非常简单,我将确保为各种特定项目执行此操作。
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:
对于通用新类(即:从VS中的“Add-> Class ...”菜单项获得的内容),这是我为实现目标所做的工作:
- Find the appropriate template Zip. On my system it was located at C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip
- Extract the zip file. This gives two files: Class.cs and Class.vstemplate
- Edit Class.cs to remove the undesired using statements. (I also changed the default class access modifier to "public" while I was here)
- Edit Class.vstemplate to remove the undesired
<reference>
elements. - Rezip the files into the existing Class.zip archive
- Replace the cached template files with the updated versions. On my system, the files were located at C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache\CSharp\Code\1033\Class.zip (a directory containing the old Class.cs and Class.vstemplate).
- I tried simply deleting this directory, expecting VS to rebuild the cache from the "original" source. This didn't work though; I got an error message saying that it couldn't find the files in the cache directory. Replacing the cached files worked well though.
我试图删除这个目录,期望VS从“原始”源重建缓存。但这不起作用;我收到一条错误消息,说它找不到缓存目录中的文件。但是,替换缓存的文件效果很好。
- Restart Visual Studio
找到合适的模板Zip。在我的系统上,它位于C:\ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ ItemTemplates \ CSharp \ Code \ 1033 \ Class.zip
解压缩zip文件。这给出了两个文件:Class.cs和Class.vstemplate
编辑Class.cs以删除不需要的using语句。 (我在这里时也将默认的类访问修饰符更改为“public”)
编辑Class.vstemplate以删除不需要的
将文件重新压缩到现有的Class.zip存档中
用更新的版本替换缓存的模板文件。在我的系统上,文件位于C:\ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ ItemTemplatesCache \ CSharp \ Code \ 1033 \ Class.zip(包含旧Class.cs和Class.vstemplate的目录)。我试图删除这个目录,期望VS从“原始”源重建缓存。但这不起作用;我收到一条错误消息,说它找不到缓存目录中的文件。但是,替换缓存的文件效果很好。
重新启动Visual Studio
Now, whenever I add a new class, I get exactly what I want.
现在,每当我添加一个新类时,我都会得到我想要的。
#2
You can change your template files... either by editing the files in the install location, or by writing a class how you want it, and choosing Export Template. There is also a template add-in somewhere...
您可以更改模板文件...通过编辑安装位置中的文件,或通过编写类的方式,以及选择导出模板。某处还有一个模板加载项......
#3
You can create your own customized item templates, see
您可以创建自己的自定义项模板,请参阅
for some details.
一些细节。
#1
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.
Marc和Brian都有一个好主意:创建一个新的自定义模板,其中仅包含我想要的使用和引用。使用导出模板,这样做非常简单,我将确保为各种特定项目执行此操作。
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:
对于通用新类(即:从VS中的“Add-> Class ...”菜单项获得的内容),这是我为实现目标所做的工作:
- Find the appropriate template Zip. On my system it was located at C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip
- Extract the zip file. This gives two files: Class.cs and Class.vstemplate
- Edit Class.cs to remove the undesired using statements. (I also changed the default class access modifier to "public" while I was here)
- Edit Class.vstemplate to remove the undesired
<reference>
elements. - Rezip the files into the existing Class.zip archive
- Replace the cached template files with the updated versions. On my system, the files were located at C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache\CSharp\Code\1033\Class.zip (a directory containing the old Class.cs and Class.vstemplate).
- I tried simply deleting this directory, expecting VS to rebuild the cache from the "original" source. This didn't work though; I got an error message saying that it couldn't find the files in the cache directory. Replacing the cached files worked well though.
我试图删除这个目录,期望VS从“原始”源重建缓存。但这不起作用;我收到一条错误消息,说它找不到缓存目录中的文件。但是,替换缓存的文件效果很好。
- Restart Visual Studio
找到合适的模板Zip。在我的系统上,它位于C:\ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ ItemTemplates \ CSharp \ Code \ 1033 \ Class.zip
解压缩zip文件。这给出了两个文件:Class.cs和Class.vstemplate
编辑Class.cs以删除不需要的using语句。 (我在这里时也将默认的类访问修饰符更改为“public”)
编辑Class.vstemplate以删除不需要的
将文件重新压缩到现有的Class.zip存档中
用更新的版本替换缓存的模板文件。在我的系统上,文件位于C:\ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ ItemTemplatesCache \ CSharp \ Code \ 1033 \ Class.zip(包含旧Class.cs和Class.vstemplate的目录)。我试图删除这个目录,期望VS从“原始”源重建缓存。但这不起作用;我收到一条错误消息,说它找不到缓存目录中的文件。但是,替换缓存的文件效果很好。
重新启动Visual Studio
Now, whenever I add a new class, I get exactly what I want.
现在,每当我添加一个新类时,我都会得到我想要的。
#2
You can change your template files... either by editing the files in the install location, or by writing a class how you want it, and choosing Export Template. There is also a template add-in somewhere...
您可以更改模板文件...通过编辑安装位置中的文件,或通过编写类的方式,以及选择导出模板。某处还有一个模板加载项......
#3
You can create your own customized item templates, see
您可以创建自己的自定义项模板,请参阅
for some details.
一些细节。