• Latest Posts

  • Latest Comments

  • Archives

Replacing the Class Template Take 1

I don’t know if it is the installation of Service Packs or something else in the environment. I’m going to document how I change my Class template for C# here and see if it stays this time. I say Take 1 because if it doesn’t, I’ll try to find out why and move on to Take 2…

There are three locations for the class template it seems in order to get it working right away. One in is my Visual Studio Projects directory, another is in the Visual Studio ItemTemplates, and the third is in the ItemTemplatesCache. On my machine these are:

  • C:\Users\Karl\Documents\Visual Studio 2008\Templates\ItemTemplates\Visual C#\Class.zip (an actual zip file)
  • C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip (an actual zip file)
  • C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache\CSharp\Code\1033\Class.zip (a file folder… despite the name it is not a zip file, that contains the two files: Class.cs and Class.vstemplate)

In this fashion I can put a region around my using statements, some copyright information at the top, some regions for code organization, and of course… to make the class public by default.

So the new Class.cs file contains this in addition to some of the other items:

#region using statements
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ == 3.5)using System.Linq;
$endif$using System.Text;
#endregion

namespace $rootnamespace$
{
    public
class $safeitemrootname$
    {

And a new class looks something like this:

I hope it stays this time. I get tired of getting my files to look right every time I create a new class.

Leave a Comment