jgauffin
jgauffin

Reputation: 101150

Adding a default namespace when a class is created

These namespaces are added per default when a class is created:

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

I want to modify existing projects or my custom project template so that additional usings are added when a new class is created.

(Instead of having to add them manually for every class. Sure, "CTRL + ." works to add namespaces for classes, but it do not work for extension methods.)

Upvotes: 4

Views: 1510

Answers (4)

Aaron McIver
Aaron McIver

Reputation: 24713

You can do this via your Visual Studio templates for particular types. In your instance you would modify the default item template for a class, however it is fine grained and you can touch multiple types, ie...interface, etc...

If you wanted to adjust the project template that can be found at...

...Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\Web\CSharp

VS seems to pull from the corresponding cache folders for the templates, to move them from the templates folder to the templates cache folder start VS using devenv /installvstemplates

Upvotes: 2

Nader Shirazie
Nader Shirazie

Reputation: 10776

Try Resharper, which has very powerful and flexible template support.

Now, when you add a new class (or indeed, a file of any type), you can select which template to use. You can share solution templates so that everyone working on the solution has the same set. Documentation for the feature is available here.

Upvotes: 1

abatishchev
abatishchev

Reputation: 100268

Go to %ProgramFiles\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\CSharp\Code\1033\Class.zip\ and edit Class1.cs and other files by analogy.

Also see %ProgramFiles\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplatesCache\..


I understand your question. You want the same behavior as Visual Basic project properties - Imports brings.

For C# - this is not possible.

Upvotes: 2

Bernard
Bernard

Reputation: 7961

You can create a template for a project and use that as the default project template in Visual Studio. Here is an article describing this process.

Upvotes: 1

Related Questions