If you want to change the default ItemTemplate of a class file in Visual Studio 2010, you can follow the steps below.
- Go to the right folder on your local machine.
- x64: C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEItemTemplatesCSharpCode1033
- x86: C:Program FilesMicrosoft Visual Studio 10.0Common7IDEItemTemplatesCSharpCode1033
- In that folder you will see the Class.zip file. If you open the class file directly from the zip, you can see the default class template of Visual Studio 2010. In my case, I want to add some default stuff like regions and constructors.
- Save the class file. It could be that you get a question that the zip file has changed and want to be reloaded. Click in that case “Yes”.
- Now, if you open VS2010, you won’t get the new class template yet. This is because the class template is not yet available in VS2010. VS2010 uses an ItemTemplatesCache directory to store the active templates. You need to override the already active template. This sounds very difficult but is very easy to do. Open your Visual Studio command prompt from the visual studio installation folder in your start menu.
(You maybe need to open it as Administrator)
Fill in this comamnd: “devenv.exe /installvstemplates”
The strange part here is that you won’t get any confirmation about the success of the installation. This could take a while because when I looked several times in visual studio, I still got the old template. After a few minuts, the new template was suddenly there.
Notes:
- It is better to close all your Visual Studio instances. before you follow these steps above.
Sample template:
/*using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
namespace $rootnamespace$
{
public class $safeitemrootname$
{
#region Constants
#endregion
#region Private Fields
#endregion
#region Private Properties
#endregion
#region Public Properties
#endregion
#region Constructors
/// <summary>
/// The default Constructor
/// </summary>
public $safeitemrootname$()
{
}
#endregion
#region Private Methods
#endregion
#region Public Methods
#endregion
}
}*/
Image: