Change Class template in Visual Studio 2010


Ralph JansenIf you want to change the default ItemTemplate of a class file in Visual Studio 2010, you can follow the steps below.

  1. Go to the right folder on your local machine.
    1. x64: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033
    2. x86: C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033
  2. 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.
  3. 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”.
  4. 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.
    image(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.

  • These steps should also work for Visual Studio 2008 but I haven’t tested it.
    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:

    image

  • About these ads

    Tags: ,

    3 responses to “Change Class template in Visual Studio 2010”

    1. Gary Rynearson says :

      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$ ?

      • LockTar says :

        Hi Gary,

        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?

    Follow

    Get every new post delivered to your Inbox.

    Join 208 other followers

    %d bloggers like this: