17

A simple question for which I couldn't find a setting or an answer:

I relocated my Documents folder in Windows to another drive. How do I change the My Code Snippets folder path in Visual Studio 2012 from the default to the new location?

The default is in my Documents folder on C:.

C:\Users\Virtlink\Documents\
    Visual Studio 2012\Code Snippets\Visual C#\My Code Snippets

But I moved my Documents folder to my drive D:, but Visual Studio didn't pick up on this change and forces the creation of the folder on C:. This causes some weird behavior with exclamation marks next to My Code Snippets in the Code Snippets Manager, and errors on importing snippets.

The folder Windows directs me to when I open My Documents from my user folder is D:\Personal\, and I want the code snippets there too:

D:\Personal\Visual Studio 2012\Code Snippets\Visual C#\My Code Snippets

If necessary, I wouldn't mind moving the whole Visual Studio 2012 subfolder. I just can't find out how to set that in Visual Studio.

enter image description here

Daniel A.A. Pelsmaeker
  • 47,471
  • 20
  • 111
  • 157

2 Answers2

17

The UI doesn't make it completely obvious what the buttons are for, but this can actually be done in two simple steps:

Step 1. In Code Snippets Manager, select the folder that points to the disk location you no longer use, and click Remove:

enter image description here

Step 2. Click Add...

enter image description here

...and select your new folder:

enter image description here

That's it! Your new folder is now active in Code Snippets Manager.

enter image description here

Reg Edit
  • 6,719
  • 1
  • 35
  • 46
  • Adding the way you said, i cant find those snippets on my visual studio when i press Clt+K & Clt+X. Where – Teju MB Jul 12 '18 at 14:31
  • 1
    @TejuMB the focus here is the folder, but if you're having trouble with a snippet file, this can be because Visual Studio holds additional metadata internally beyond what the snippet XML defines. If you're manually placing a snippet file or editing it directly in a snippet folder Visual Studio knows about, this can break things. See this answer for an example that may shed light on the problem you're seeing: https://stackoverflow.com/a/51329480/1657610 – Reg Edit Jul 14 '18 at 11:20
4

Code Snippet folders don't seem to be directly editable in the Visual Studio IDE (that I could find). They are stored as registry entries, so you have to edit these settings directly.

For Visual Studio 2012 the registry settings are located in:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\Languages\CodeExpansions\Visual C#\Paths

The value is called 'Microsoft Visual CSharp', and lists all the different folders separated by semicolons:

%InstallRoot%\VC#\Snippets\%LCID%\Visual C#\;%InstallRoot%\VC#\Snippets\%LCID%\Refactoring\;%MyDocs%\Code Snippets\Visual C#\My Code Snippets\

The quick fix for the snippets would be to provide the full path in place of the %MyDocs% setting.

I couldn't find a reference to how %MyDocs% is defined, but I suspect it's the "Projects Location" setting:

Tools -> Options -> Projects and Solutions/General

Quango
  • 12,338
  • 6
  • 48
  • 83
  • %MyDocs% refers to `HKCU\Software\Microsoft\VisualStudio\12.0\VisualStudioLocation`. See [this question](http://stackoverflow.com/q/6395057/21475). – Cameron Jan 15 '14 at 20:36
  • Thanks, the battle to keep a usably organised Windows documents folder is one of constant vigilance, but that's one more off the list of pests. – Jon Hanna Apr 30 '14 at 11:52