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.
- It is better to close all your Visual Studio instances. before you follow these steps above.
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
public class $safeitemrootname$
#region Private Fields
#region Private Properties
#region Public Properties
/// The default Constructor
#region Private Methods
#region Public Methods
3 thoughts to “Change Class template in Visual Studio 2010”
Excellent instruction set – easy to follow and effective. However, maybe you would consider placing at the top of the instructions the Note requesting VS be shut down first ;).
BTW, do you know where I can find a list of placeholders, like the $targetframeworkversion$ ?
Thx for the feedback! I will use the feedback for my next blogpost.
Sorry I don’t know were you can find that kind of list. It was for me a while ago when I made a template for Visual Studio. In this case I only needed to add some regions for a quick overview of the class.
A while back, I made a whole solutions template with 15 or so projects in it. Next month, I need to make a new Solution Template, so I will blog about it ones again. Maybe you can use that information for future projects?
FYI. I found a list of template parameters at http://msdn.microsoft.com/en-us/library/eehb4faa.aspx. Looks like at least a good starting point.