views:

34

answers:

2

In Visual Studio 2008 C#, if I create a new class the following namespaces appear by default and I remove them manually every time. Is there a setting/folder template where I can go and remove these unwanted namespaces from appearing on each and every new class that's created on the project?

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

+2  A: 

This is coming from the ItemTemplate for a new class. Go to

[Program Files]\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033

(possibly a different LCID if you have a non English installation), and you can alter Class.cs inside Class.zip to fit your needs. Then clear out the cache at

[Program Files]\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplateCache

You should find your classes now get created in whatever way you just altered the template. Keep in mind this is not supported behavior, you are effectively "hacking" VS (although in a very trivial way)

The supported way to do this is to create your own template and use that, as shown here: http://www.switchonthecode.com/tutorials/visual-studio-how-to-create-item-templates

Matt Greer
+1  A: 

To add to Matt's answer, you will find that depending on the project type you will see different sets of namespace imports. I suspect these are separate templates but some of the templates may be difficult or impossible to modify depending on how they were implemented. For example in a WPF or Silverlight application you get a whole bunch of System.Windows.* imported namespaces that you don't see in a normal class library project.

Another option would be to map a key sequence to the RemoveAndSortUsings command. If you go to Tools -> Options -> Keyboard you will see the keyboard shortcut interface. Just type "sort" and you should find the command, then map some key sequence to it and you can easily invoke that command whenever you want to tidy things up.

Josh Einstein