This is a really short article on an interesting subject. It is intended to show how easy it is to change the default C# templates used when new items are created within Visual Studio .NET 2003. This can really come in handy, for example if you want to include a fixed comment in all your classes or use Visual Source Safe keywords to generate a log history within each class file.
Most programmers have to follow some company centric programming procedures and I am no exception. Where I work we have to include fixed comment headers in all classes we create and we use Visual SourceSafe keywords to keep track of the class history within the class file (VSS keywords are a way to allow VSS to place certain information directly into your file to create a file header for you).
Leave it to Murphy - Of course, it was very common to find classes all over the place that did not adhere to the procedure. People forgot to add the comments, the keywords or both. So, we thought of changing the Visual Studio template files for class creation. The result of that effort is the main topic of this article.
I want to make it absolutely clear that this article does not focus on VSS keywords or a technical explanation of Visual Studio .NET wizard templates. Other articles or sources have covered these issues already and so adding my take would probably be a bit redundant. If you want to familiarize yourself with either wizard templates or VSS keywords then please visit the links found in the "Further Information" section.
The wizard template files for C# can be located in the following directory: [Visual Studio .NET 2003 Install Directory]\VC#\VC#Wizards. In my case that would translate to: C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards. Each [...Wiz] directory contains the "Templates\1033" directories. Each "1033" directory contains the template file for the corresponding wizard. If I wanted to change the template for normal classes on my local computer, I would edit the following file: C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards\CSharpClassWiz\Templates\1033\NewCSharpFile.cs. Relatively easy stuff. Therefore, the edited version of my class template includes a default comment and a couple of VSS keywords. It looks like this:
namespace [!output SAFE_NAMESPACE_NAME]
public class [!output SAFE_CLASS_NAME]
public [!output SAFE_CLASS_NAME]()
Of course, this cute little article is fixed on C#. Wizard templates for other VS.NET 2003 supported languages are also easily customizable. For example, my wizard templates for Visual Basic or J# can be located here:
- C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards
- C:\Program Files\Microsoft Visual Studio .NET 2003\VJ#\vjsharpwizards
Please note that these are absolute paths derived from the setup of my system.
For further information on the template files visit:
For further information on VSS keywords (and more VSS goodies) visit:
- 7th August, 2005:
- Added a couple of chapters to set up a context for the article.
- Added "Revision history".