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;
You could put the caret on a namespace declaration in your C# code and press F2 on the keyboard. This should let you change the name of the namespace across the entire project, including the XAML files.
First is putting your cursor on one of the grayed out lines and clicking the light bulb, then clicking Remove Unnecessary Usings. (NOTE: The shortcut key for this is CTRL-.)
You can change the default namespace: -> Project -> XXX Properties... Instead of Find/Replace, you can also right click the namespace in code and Refactor->Rename.
VB.NET uses the name of your project (WindowsApplication1 for a standard forms application if you don't change it) as the default namespace.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With