Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 586
Chris S Avatar asked Jan 05 '12 16:01

Chris S


People also ask

How do I change Visual Studio default settings?

Reset settingsSelect Tools > Import and Export Settings from the menu bar to open the Import and Export Settings Wizard. In the Import and Export Settings Wizard, select Reset all settings, and then select Next. On the Save Current Settings page, select either Yes or No, and then select Next.

How do I change the default C++ version in Visual Studio?

To set this compiler option in the Visual Studio development environment. Open the project's Property Pages dialog box. For more information, see Set C++ compiler and build properties in Visual Studio. Select the Configuration Properties > C/C++ > Language property page.

How do I change the default language in Visual Studio?

The standard wayOn the tab Installed, click button Modify next to the version of Visual Studio you need the English language pack for: In the next window, select Language packs tab, tick the English language and then accept changes by clicking Modify button (right bottom corner).


Video Answer


2 Answers

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.

like image 87
Darin Dimitrov Avatar answered Sep 29 '22 12:09

Darin Dimitrov


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.

like image 40
Steve B Avatar answered Sep 29 '22 10:09

Steve B