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

2

18

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

Lobel answered 18/3, 2013 at 13:46 Comment(3)
Has any of the provided answers worked-out for you? If so, please consider marking that one as solution :)Thorne
@MarcusMangelsdorf None of the solutions worked for me at the time, and I haven't tried it since.Lobel
Hi, which methods did you use from 2 answers?Clipping
T
18

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

Tamatamable answered 6/5, 2015 at 8:43 Comment(2)
Adding the way you said, i cant find those snippets on my visual studio when i press Clt+K & Clt+X. WhereDonatelli
@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://mcmap.net/q/741303/-vs13-vs15-can-39-t-import-sql-snippetTamatamable
A
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

Altercation answered 29/11, 2013 at 10:28 Comment(2)
%MyDocs% refers to HKCU\Software\Microsoft\VisualStudio\12.0\VisualStudioLocation. See this question.Penza
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.Kermie

© 2022 - 2024 — McMap. All rights reserved.