INTELLIGENT.TECHNICAL.ARCHITECTURE.TRAINING

 
 
Blogs:
 
 

Changing the default item templates in Visual Studio 2005

April 27, 2005 / 1 Comment
AUTHOR:
CATEGORY: .Net


If you use the Add Item menu to insert a file into your Visual Studio 2005 project, the resulting file may not meet your needs by default.  However, these default files can be modified to suit your fancy.

The item templates directory is located in “%ProgramFiles%\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates” by default.  It contains a folder structure for the various programming languages and file types.  In the “CSharp\1033” (assuming English) directory are the C# item files.  Interestingly, however, each item template is stored in a zip file along with a *.vstemplate file.  Since we are only modifying existing templates I won’t discuss the details of the vstemplate file (these are available here).  And, modifying the item template file is relatively obvious.  Adding the public keyword, for example results in a class.cs file as follows:

using System;
using System.Collections.Generic;
using System.Text;

namespace $rootnamespace$
{
public class $safeitemrootname$
{
}
}

It is here that modifications to the default using declarations can be made as well.

However, modifying the item template file is not all that is required.  Along side the “%ProgramFiles%\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates” directory is a “%ProgramFiles%\Microsoft Visual Studio 8\Common7\IDE\ItemTemplatesCache” directory that contains extracted copies of the ItemTemplates directory.  (Michael Stokesbary mentions this in his post on the same topic.)  This directory is created during setup and it is the location that Visual Studio 2005 pulls item templates from.  Therefore, you need to modify the content in this directory too.  (Notice that the directory names for each item template end with “.zip”)

Miscellaneous notes:

  • There is also a “%ProgramFiles%\Microsoft Visual Studio 8\Common7\IDE\NewFileItems” directory that also contains a class template that is different from the ItemTemplate C# class file (it uses the public accessibility modifier).  These templates are used by the File->New Item menu.
  • Visual Studio 2005 includes an option for re-running the final setup stages.  The command is “Devenv /Setup” and it recreates the ItemTemplatesCache directory so if they become hopelessly out of sync. you can correct the problem that way.  (Devenv /Setup” does not show up as an option in the Devenv /?” command.)  On my computer, upgrading from Beta 1 Refresh to Beta 2 required running this command after installing Beta 2 in order to fix up my both my project and item templates.  Before running “Devenv /Setup” I had languages item directories such as “P” among other peculiarities.

 

IntelliTect Corporation
3024 S. Bannen Ct.
Spokane Valley, WA  99037

Phone: (509) 720-8842
Email: info@intelliTect.com

  COPYRIGHT © 2010 INTELLITECT. ALL RIGHTS RESERVED.