Tuesday, 27 May 2008

Visual Studio templates

Visual Studio 2008 sticks a bunch of using statements at the top of any new C# source file. They include System.Collections.Generic and System.Linq. I tend to not use these for my current projects, but instead to use System.Collections.ObjectModel (where Collection<> lives) and System.Xml.Linq (where XElement etc live).

After a little poking around, here's what you do to change the template:

In %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip

is a template called Class.cs. Edit it to say something like this:


using System;
using System.Collections.ObjectModel;
$if$ ($targetframeworkversion$ == 3.5)using System.Xml.Linq;
$endif$

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


Save it back into the zip file and run


devenv.exe /setup


Then restart Visual Studio and all is good.

One caveat: I am not sure exactly what features might get reset by running with the /setup option. It didn't trash my custom font settings at least.

No comments: