4

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.)

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

All projects are not going to use the usings. I either want to modify existing projects or my project template.
@jgauffin: Unfortunately this feature is for VB.NET projects only. In C# you should always add all usings used
I have installed VS 2010 Premium Edition, however I don't find any such folders as they stated above. 1. C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies 2. C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Xml. Is there any other place I need to look in.
@Elan: Don't you use x64 OS? So take a look in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
2

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

4 Comments

How do I do it for a specific project? Not for all projects of a certain type (for instance ASP.Net Project).
There are project templates and item templates...for the web based item templates look here...\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\Web\CSharp
See the second part of my answer to clarify what does OP really ask for.
@abatishchev Updated answer to reflect more of what the OP is going after
1

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.

3 Comments

That page is for vb.net, <Import> cannot be used for cs projects
@jgauffin: It's a shame that the article doesn't provide an example for C#, but the principle is still the same.
Nope. I've just check all possible elements in the csproj file and there is not a corresponding element for csharp.
1

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.

1 Comment

I use Resharper myself, but my current client do not and will not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.