50

How do you change the location for the "Visual Studio 2017" directory that is created under %USERPROFILE%/Documents?

In 2015 and earlier, you could move all the folders out of "My Documents" by editing the registry, but those values seem to have moved for VS2017:

The old way: Change "Visual Studio 2010" folder location

Update

I have changed the default Projects and Templates locations, but these directories persist in My Documents:

Directories in My Documents

Community
  • 1
  • 1
Duodenalsalmons
  • 652
  • 1
  • 7
  • 13

3 Answers3

65

(Starring this question because I'm going to need this answer for the next release of Visual Studio, I bet... And I forget this every time I set up a new machine. I cobbled this together last time from a bunch of different sites, but unfortunately my google-fu cannot find them again, so my sincerest gratitude to those unnamed developers.)


Finally, a question I can answer! I, too, have spent countless hours trying to fix this. The commenter on your question is correct--the settings are still controlled by the same registry keys, it's just that the location of those has been moved following the switch to a different installer. Lo and behold:

  • Previously, Visual Studio installed many registry keys into the system’s HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER hives under a Visual Studio-specific key:
    • HKLM\Software\Microsoft\VisualStudio\Version: [...]
    • HKCU\Software\Microsoft\VisualStudio\Version: [...]
    • HKLM\Software\Microsoft\VisualStudio\Version_Config: [...]
  • To reduce the impact on the registry, Visual Studio now uses the RegLoadAppKey function to store registry keys in a private binary file under %VsAppDataFolder%\privateregistry.bin. [...]

So in essence, what you need to do is to find that file, load it in a registry editor (such as regedit.exe), change the values to your liking, and then save the file in the same format. On my machine, the file was located in:

C:\Users\Ernest\AppData\Local\Microsoft\VisualStudio\15.0_dfee2c30

Not censoring my username 'cause it's pretty obvious anyway. The following is how to use regedit.exe to do the editing:

First, select somewhere to load the registry hive (I used HKEY_USERS). It doesn't really matter as long as you don't overwrite something when loading the hive (it will warn you). With that key selected, go to File > Load Hive..., and open the aforementioned privateregistry.bin file. Type in a Key Name to load it under (e.g. "VS2017_config"), and you'll see the familiar keys used in past versions to configure paths. Change those. When you're finished, select the hive which you loaded (e.g. "VS2017_config"), and go to File > Unload Hive.... This should set folder paths correctly.


Do note that those folders will pop up again the first time you use Visual Studio Blend, so remember to change those as well if you ever plan on using that.

Edit: The corresponding registry hive for Blend was here for me:

C:\Users\Ernest\AppData\Local\Microsoft\Blend\15.0_dfee2c30


Edit 2018: @ofthelit has kindly posted an official page with the relevant info.

Ernest3.14
  • 1,012
  • 11
  • 21
  • 3
    Excellent - this worked perfectly. Thanks very much! – Duodenalsalmons Mar 20 '17 at 17:43
  • 2
    These folders were reset after a Visual Studio Repair as well, but only a 5 minute fix to load/edit/unload the hive – Duodenalsalmons May 02 '17 at 11:09
  • 2
    _In Visual Studio 2017, registry settings are stored in a private location, which enables multiple side-by-side instances of the same version of Visual Studio on the same machine._ Documentation location: https://learn.microsoft.com/en-us/visualstudio/install/tools-for-managing-visual-studio-instances – ofthelit Mar 15 '18 at 10:00
  • Downvoting because I strongly believe @David's answer is concise and much better for the average user. These steps are not likely to be supported/maintained by Microsoft. – lightw8 Sep 13 '18 at 16:26
  • That's fair, as of the time I wrote the answer I couldn't find the relevant documentation. However, as of the writing of this comment, @ofthelit posted official documentation regarding this [here](https://learn.microsoft.com/en-us/visualstudio/install/tools-for-managing-visual-studio-instances?view=vs-2017) – Ernest3.14 Sep 13 '18 at 20:32
  • So far the first preview of VS2019 appears to follow the same pattern. – Chris R. Donnelly Dec 13 '18 at 21:11
  • Interesting, what will happen if we change the `MyDocumentsLocation` value in `privateregistry.bin`? What will be the effect of doing this? It would be nice if it could help to move ALL VS folders outside of the default Documents folder at one go... – TecMan Dec 19 '18 at 09:27
  • Does this still work for you? I followed your entire process for Visual Studio 2017 on windows 10, and I can't seem to prevent it from creating those pesky folders directly within the solution and projects directories. what keys did you change in order to get this to work? – TwitchBronBron Jan 24 '20 at 20:00
  • I was using your method with VS 2017. However, VS 2019 seems to regenerate the original privateregistry.bin file once I open it again, overwriting my settings. Any ideas for that? – florien Oct 03 '20 at 17:16
  • 1
    I figured it out: if you set the MyDocumentsLocation not to your real documents location, then the file will be regenerated. Otherwise it's accepted. – florien Oct 03 '20 at 17:28
28

Or (in Visual Studio 2017) just go to tools >> options >> projects and solutions >> Locations

enter image description here

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
David
  • 3,488
  • 2
  • 21
  • 21
  • 2
    Well, the regedit of VisualStudioLocation is superior as it changes all at once including Code Snippets location. (Also, Visual Studio always creates a "My Snippets" for Visual Basic [even if you delete it], the location of which can only be changed using the regedit method.) –  May 23 '18 at 06:49
  • 2
    Yeah, the reason I even posted my answer is that just changing these settings still leaves pesky folders around that aren't removed. If you don't care about those, I agree that this is a fine answer. – Ernest3.14 Sep 13 '18 at 20:28
  • 1
    Regarding "dangerous regedit", it's a separate hive from the registry entries for your entire computer, so anything that you fuck up can be easily repaired by the VS installer. (If you had actually read my answer...) It's not your typical "change a bunch of registry entries to 'fix' your computer". – Ernest3.14 Sep 13 '18 at 20:31
  • 1
    This only changed the location of templates for me, not the whole "Visual Studio 2017" directory. – Chris R. Donnelly Dec 13 '18 at 20:27
  • @chris-r-donnelly Helped my anyway as after changing whole "Visual Studio 2017" directory those two template still get autocreated. – jifb Jan 19 '23 at 12:54
0

If you have source control enabled for the Project, in addition to the step as answered by David, you have to also map the TFS local path location to the new Project location :

In VS 2017: 
File -> Source Control -> Advanced -> Workspaces -> Edit the relevant 
Workspace -> Select the Project -> Edit path to Local Folder to be the new 
location.
Jaggan_j
  • 488
  • 1
  • 8
  • 9