February 21, 2006
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 Files\Microsoft Visual Studio 8\VC#\Snippets\1033\
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:
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 ..
.. to wired ..
.. 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)
Posted by Jeff Atwood
Thanks! Much improved over MS' "installation"
Interestingly enough, I can not find the "Code Snippets Manager" on my VS2005 Tools menu.
All the MSDN2 Articles just assume it will be there, and I haven't yet figured out how to force it to show up either.
Dunno if WinRAR supports [self-extracting archives], but the 7zip program does.
I agree, but when the archive is only 60kb to start with, the overhead of the self-extracting EXE is a little too much to bear ;)
I second Jon Galloway on the Darwinia accusation! Though the code snippets aren't going to save me any time.
Jeff Ah, ok. So I _was_ missing something! :)
Malcolm On one of my VS installations, I had no menu item either, for some reason. I added it myself by... Right-click on the menu, choose Customize, go to the Commands tab, from the Categories list click Tools. In the right-hand list you should see it listed as Code Snippets Manager. Drag-and-drop it from there to wherever you want it in the menu. Works?
Interestingly enough, I can not find the "Code Snippets Manager" on my VS2005 Tools menu
Use the keyboard shortcut I mentioned in the post: CTRL+K, CTRL+B
Same issue with Team Developer installed. It doesn't appear in the menus by default. This can of course be customized.. Frederik described how to add it.
I can highly recommend IZArc [http://www.izarc.org/] which is freeware. It uncompresses most formats and can compress to zip, 7-zip and a bunch of others (not rar though).
I like the interface better than WinZip or WinRAR.
Maybe I'm missing something, but for me, installing these snippets using the Microsoft download was easy-peasy. I just added the root folder (in my case, D:\Documents\MSDN\Visual C# 2005 Code Snippets\) in the Code Snippet Manager and everything 'just worked(TM)'. No manually adding each folder for me! Weeee!
I like 7-Zip just as it is. :-) Sure, there's room for improvements, but it's free and it basically does everything I need it to do.
Anyway, thanks for the "installer". I did download Microsoft's MSI packages a while ago, but I didn't install all of them for the same reason you describe.
I just added the root folder (in my case, D:\Documents\MSDN\Visual C# 2005 Code Snippets\) in the Code Snippet Manager
I wanted the snippets in the same folder as the "standard" C# set-- which means you have to add each folder individually.
But you can add an arbitrary new folder, or put the snippets in your user snippet folder.
Leave it to a VB developer to make it easier... ;-)
Jeff man, thanks for this! We owe ya.
After installing the C# code snippets, I have an extra folder that appears in the pop-up as shown in this picture: a href="http://pics.bbzzdd.com/users/mrmilney/snippets_popup.gif"http://pics.bbzzdd.com/users/mrmilney/snippets_popup.gif/a
The 1033 folder does not appear in the snippets manager dialog as you can see in this picture: a href="http://pics.bbzzdd.com/users/mrmilney/snippets_manager.gif"http://pics.bbzzdd.com/users/mrmilney/snippets_manager.gif/a
I have looked and looked in vain, but I can't see where this extra entry is stored in either the registry or in any configuration files in the VS 2005 directory. I'd appreciate any help anyone could give me.
I apologize for the bad links in the above post, if anyone wants to see the pics I will be glad to e-mail them to you.
The problem is this: when I type ctrl+k, ctrl+x to bring up the Insert Snippet pop-up in VS.NET 2005, the topmost folder in the list is 1033. If I bring up the Code Snippets Manager with ctrl+k, ctrl+b the 1033 folder is not listed (and therefore I can't remove it).
I have checked both the registry keys referenced in the add-csharp-snippets.reg file, but I can't see where this extra entry is coming from. It seems that VS 2005 is hiding the snippet paths somewhere else, but I can't figure out where. If anyone has any suggestions, I'd love to hear them.
The registry is the master source, no doubt about it. Check both local and user keys:
Beware, the path is duplicated within these keys-- check for a "Path" subkey. I have no idea why, but it is.
You can validate this yourself by adding a new path in the snippet manager. If you check the reg key afterwards, you'll see it is there..
I agree that the snippet entries _must_ be in the registry, but I can't seem to find the one I need to remove this extra folder. I even went so far as to manually add "%InstallRoot%\VC#\Snippets\%LCID%;" to both path keys under HKCU. While this did make the 1033 entry appear in the Code Snippets Manager, removing it from there did not make the problem go away.
Does anyone have any further suggestions? My OC is kicking in and that extra folder is really bothering me.
Joe, it's really weird that there is a mismatch between what the snippet manager shows and what shows up in the IDE! I have no idea what's going on there, but triple check all those registry keys and sub-keys.
Could you update the link.
The link works for me:
I checked in IE6 and Firefox 1.5.
My 2: 7-Zip rocks.
My own little rant, cut and pasted from an email
Everyone should be using 7-Zip. But the best way to get everyone using it is to get your friends to install TugZip. TugZip ( http://www.tugzip.com/ ) is the best windows archiver I've ever used. Its integration into the file manager is awesome, and it's completely free!
Not only does it allow right-click creation of archives and unzipping multiple archives at once (each into it's own directory), but it allows you to customize the icons for each type of archive that it supports, and lets you set the default compression level (including creating solid archives) for those right-click "add to .7z" actions.
The only thing it CAN'T do is CREATE rar archives (without rar.exe). But it does unpack them with no problems, which is all I care about, since I'm making 7-Zip, not rar.
For all of you who're seeing folders that aren't there when pressing CTRL-K + CTRL-X, the key is to delete this folder:
C:\Documents and Settings\%User%\Local Settings\Application Data\Microsoft\VisualStudio
Next time you start VS it'll get fixed.
Brilliant! It worked perfectly. Thank you very much. (If you have a minute, would you mind sharing _how_ you discovered that? I'd really like to know.)
I simply figured if its not in the registry, where the heck can be stored?
After 30 minutes of inspecting all the appdata/local settings/etc inside my username (you'd be amazed the amount of crap I found--this is a 2-years old install) I found that VS folder so I decided to delete it, and well, it worked. :)
If you really need to know the following file is what contains these "extra" folders:
C:\Documents and Settings\user\Local Settings\Application Data\Microsoft\VisualStudio\8.0\1033\ExpansionsXML.xml
Edit this file to remove the extra ones.
For those of you using Visual Studio Express open the reg file and replace 'VisualStudio' with 'VCSExpress' in each path.
Thank you all for posting your comments.
They ALL helped me get not only the Snippets working OK but you also helped me understand the whole VS2005 Dev IDE a little bit better.
One thing though - when you are looking for a solution to a problem that shouldn't be a problem (and boy this definitely falls into this category) there is nothing more that pisses me of than having to instal another proggy just to get the original problem solved.
Until now I'd never heard of 7.thingErMeJig and until I have a lot of spare time I probaby won't again.
Once again, sincere thanks to you all...
joe paris, i was having the same issue as you were. their decision for microsoft to do it like that was asinine.
however, thanks to Edgardo and MikeWo for your replies to this thread. it was driving me crazy, but now i'm where i need to be.
That was really cool. Especially finding the Code snippet manager helped me a lot! I was shocked when I didn't find it under my tools menu!
Best of luck
Thanks for this code snipped.It helped me a lot!
Pefix from Sicily!!
code snippets are coooool!
The files are not on the MS site anymore. Thanks for saving them.
Does anybody know how you can make snippets "double tappable"?
For example: if I type "if"+double tab, the whole if structure is inserted. I would like something simmilar with some other snippets too.
how to disable right click in c# form
Yay! Now I'm snip-a-licious too!
My mom would be so proud!
No, seriously, thanks for doing this. This just about makes up for the loss of an evening on Darwinia, which is totally your fault.
As for 7z, I totally agree that it's a better format, but since it's still a 733t h4x0r format I usually make them self extracting exe's (sfx's). Dunno if WinRAR supports it, but the 7zip program does.