C# Snippet Parity

Microsoft recently released a complete set of C# code snippets for Visual Studio 2005. This brings C# to parity with VB.NET, which had many more code snippets "in the box".

Unfortunately, Microsoft's installation strategy for these new snippets leaves a lot to be desired. You can download and "install" all the snippets at once, but you must manually add each of the snippet folders via the Snippet Manager (Ctrl+K, Ctrl+B). I loves me some snippets, but this is unacceptable!

The snippets themselves, of course, are just individual XML files that end in .snippet sitting in a bunch of folders. There are two valid snippet paths: per-user and system-wide. The system-wide C# snippet path is:

C:Program FilesMicrosoft Visual Studio 8VC#Snippets1033

There's an index file in that folder, SnippetsIndex.xml, which appears to store the snippet paths. You might think editing this file would cause the folders to appear in the snippet browser (Ctrl+K, Ctrl+X). Seems logical, right?

Unfortunately, it's not that easy.

I think that file may be used the first time the IDE is initialized, but edits to that file don't appear in the Snippet Manager.

The real snippet paths are stored in the registry at:

[HKCUSoftwareMicrosoftVisualStudio8.0LanguagesCodeExpansionsVisual C#]

Why they chose to store this stuff in the registry and in an XML file is beyond me. Anyway, I packaged the correctly pathed snippets and a registry file together. Now you can quickly get the snippets installed on your system without running a pointless installer that does virtually nothing for you.

You can go from tired ..

Aww, C# has hardly any snippets

.. to wired ..

Just like VB.NET snippets! Viva le squiggly!

.. in no time at all. If you've forgotten the keyboard shortcuts for snippets, revisit my snippet blog entry to refresh your memory.

Microsoft provides 295 new C# code snippets, and they're 508 KB in total size. I chose to package the snippets as a 7zip file for compression efficiency:

  • ZIP: 229kb
  • RAR: 73kb
  • 7Zip: 56kb

To be fair to ZIP, it probably would have done better if the format supported solid archiving for this set of small files.

To decompress the archive, I recommend switching to WinRAR if you aren't already. It supports 7zip as well as RAR and ZIP, but more importantly, it won the best archive tool DonationCoder roundup. I'm not a huge fan of the UI, but I encounter RAR files often enough that WinZIP isn't cutting it any more.

Download C# snippets and registry file (60kb 7zip archive)

Read more

Stay Gold, America

We are at an unprecedented point in American history, and I'm concerned we may lose sight of the American Dream.

By Jeff Atwood · · Comments

The Great Filter Comes For Us All

With a 13 billion year head start on evolution, why haven't any other forms of life in the universe contacted us by now? (Arrival is a fantastic movie. Watch it, but don't stop there - read the Story of Your Life novella it was based on

By Jeff Atwood · · Comments

I Fight For The Users

If you haven't been able to keep up with my blistering pace of one blog post per year, I don't blame you. There's a lot going on right now. It's a busy time. But let's pause and take a moment

By Jeff Atwood · · Comments

The 2030 Self-Driving Car Bet

It's my honor to announce that John Carmack and I have initiated a friendly bet of $10,000* to the 501(c)(3) charity of the winner’s choice: By January 1st, 2030, completely autonomous self-driving cars meeting SAE J3016 level 5 will be commercially available for passenger

By Jeff Atwood · · Comments