How can I change the default Visual Studio C# new class file template? [duplicate]

Is it possible to change the template in Visual Studio 2010 so that the class definition is changed from:

class Class1
{

}

to:

public class Class1
{

}

When creating a new class via Add->Class in the context menu.

I would also ideally like to be able to create a class in one context menu click. I copy+paste existing class files to avoid the file dialog.


You could modify the following file:

c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip

It contains the template used when you add a new class. Inside the same folder you also have the template for interfaces: Interface.zip so that they are public by default. IIRC a restart of VS is necessary to pick the changes.


You can create your own template by putting a file in C:\Users\you\Documents\Visual Studio 2010\Templates\ItemTemplates\Visual C#.

For example, you can put "publicclass.cs" with this content :

using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;

namespace $rootnamespace$
{
    public class $safeitemrootname$
    {
    }
}

In order to avoid the class dialog, you can use the smart tag. Anywhere you would to use an inexisting class, simply type the class name, and press AltShiftF10 to popout the "generate class" menu.