views:

78

answers:

3

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

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

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

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?

+3  A: 

You're looking for the following directory:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp

Each template is a ZIP file inside the 1033 (English) subfolder of one of the categories in this folder. You can edit the .cs file inside the ZIP file.

If you're on a 32bit system, remove the (x86). VS2005 is Microsoft Visual Studio 8, and VS2010 is Microsoft Visual Studio 10.0.


Note that these templates are not per-user. You can make per-user templates by copying those ZIP files to My Documents\Visual Studio 2008\Templates\ItemTemplates\Visual C#.

SLaks
+3  A: 

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

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

2005: C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\CSharp\1033\Class.zip

2008: C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip

2010: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip

280Z28
Thanks! The tip about assembly references was a nice bonus :-)
Jørn Schou-Rode
It doesn't always reflect these changes in Visual Studio. If it doesn't for you, edit the files in the `ItemTemplatesCache` directory (in addition to `ItemTemplates`). E.g. (in 2005) `C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache\CSharp\Code\1033\Class.zip\Class.cs`. Note that `Class.zip` here is a directory, not an actual ZIP file.
Arc
A: 

Here are a couple of links I found useful in the past when working with templates:

http://msdn.microsoft.com/en-us/library/ms247115(VS.80).aspx

http://msdn.microsoft.com/en-us/library/6db0hwky(VS.80).aspx

Unfortunately the second lost the example images.

I find it really helpful to create my own templates for commonly used types of files in my projects (so that I can start out using the proper namespaces, inheriting from certain classes etc). Ex: for a web form I can inherit from my own base page class and throw in a couple of standard using statements that would apply to that type of file. Also since I am a bit anal with code formatting I tend to use code regions a lot and it is nice to setup some regions that I know I will use.

Jim Petkus