Adding a default namespace when creating a class

These namespaces are added by default when the 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 to add additional additions when creating a new class.

(Instead of adding them manually for each class. Of course, “CTRL +.” Works to add namespaces for classes, but it does not work for extension methods.)

+4
source share
4 answers

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 need the same behavior as the properties of a Visual Basic project - Import brings.

For C #, this is not .

+2
source

You can do this with Visual Studio templates for specific types. In your instance, you must change the default element template for the class, however it has a fine-grained structure, and you can relate to several types, that is ... an interface, etc.

If you want to customize the project template, which can be found in ...

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

VS seems to be extracting from the corresponding template cache folders to move them from the template folder to the template cache folder, launch VS using devenv /installvstemplates

+2
source

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

+1
source

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 choose which template to use. You can share solution templates so that everyone working on the solution has the same set. The documentation for this feature is available here .

+1
source

All Articles