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.0Common7IDEItemTemplatesCSharpCode1033
    2. x86: C:Program FilesMicrosoft Visual Studio 10.0Common7IDEItemTemplatesCSharpCode1033
  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

  • How to change the setup.exe icon

    Ralph JansenIf you create an application, you have also create an installer project. The installer creates two files for you. An setup.exe file and a msi file. The icons of the two files are set by the default windows icons. In Windows 7 it looks like this: image

    If you want to change the icon of the installer, you can not do that by default in your installer project. Also, the icon of the msi file can not be changed at all. For the setup.exe file you have to do it manually for each time you create a new installer. So every time you fix a bug and releases a new version of your application by the new created installer you have to set the icon manually. Lucky that this is not hard to do.

    Change the icon

    1. Create an installer project with the right settings that you want and build it.
    2. Now open the setup.exe file in the release folder (that is the one that you want to give to your client) in Visual Studio. You can do this as follow:
      1. Click in Visual Studio on File –> Open –> File
      2. Navigate to the exe in the release folder
      3. Click open and then you will see an explorer in Visual Studio
        image
    3. Right click with your mouse on the icon folder and choose “Add Resource…”
    4. The icon type is now selected by default. Choose on the right of the popup for “Import”
    5. Navigate to the right icon that you want and select it
    6. The popup will now close and the icon folder in the explorer is expanded
    7. Make sure that your new icon has the lowest ID. If you don’t do that, the icon will not been shown
      image
    8. Save the setup.exe and return in Windows Explorer to the release folder. You should now see the new icon.
      image