Daniel A.A. Pelsmaeker
Daniel A.A. Pelsmaeker

Reputation: 50366

How to move Visual Studio's 'My Code Snippets' folder to another drive?

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

Upvotes: 18

Views: 13015

Answers (2)

Reg Edit
Reg Edit

Reputation: 6924

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

Upvotes: 18

Quango
Quango

Reputation: 13468

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

Upvotes: 4

Related Questions