VS 2005, File Templates, Snippets

So I FINALLY got my own copy of Visual Studio 2005 Professional, and it was a good deal too (thanks to a friend). I got some free CTP drops a while back that I played with, and beta 2, but when the real thing came out I had to stick with the Express edition at home (it was pretty nice, actually). At work, however, I spend just about all day in VS 2005 Professional. Anyway, it’s nice to have my own copy. And it even came with a pretty handy book.

One thing that I’m going to end up spending quite a bit of time on is customizing and extending VS. Doesn’t that sound like fun? Today I spent time with file templates and snippets.

Ever want to edit the default file templates? Of course you do. I wanted to because I’m doing some 1.1 work using the 2.0 studio, so I had to write code that was backwards compatible. This means no generics. And, of course, what namespace shows up in the default class file template for C#? System.Collections.Generic. So I wanted to take that out.

You would think you would go to the C:\Program Files\Microsoft Visual Studio 8\VC# area. That’s where snippets are. Nope. You might also think that you go to C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\CSharp\1033. Nope, but you’re warmer. You actually go to C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplatesCache\CSharp\1033. You can change those files, and the changes should be applied next time you restart VS.

So, what about snippets? That’s when you go to C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#. Snippets are Xml based files, but it is pretty easy to understand what is going on. Edit those files, restart visual studio, and presto!

The hotkey combo for snippets in VS is pretty awkward, Ctrl+K, Ctrl-X. I’m trying to think of something a little easier on the fingers, because I am trying to snippet things more and more.

BTW, if you haven’t used snippets in VS 2005, take a look at them. They can be useful.


Jason Marsell 2006-03-21 12:33:00

Your post rocks...I was (coincidentally) looking for the snippet hotkey and the template location, and your post addressed both. One stop shopping.