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

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.

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:
Step 2. Click Add...
...and select your new folder:
That's it! Your new folder is now active in Code Snippets Manager.

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

Related

How can the Solution Explorer in Visual Studio Community 2019 be refreshed?

I have a basic c++ project in Visual Studio Community 2019. It contains three files: main.cpp, log.cpp, and log.h. I created a fourth file called Source.cpp and then deleted this file from the file explorer in Windows 10 to see how Visual Studio would adapt to external changes to files. Source.cpp is still visible in the solution explorer in Visual Studio.
I have tried unloading the project and reloading it but it still appears in the solution explorer. I assume it's best practice to delete files from within Visual Studio's solution explorer but there must be a way to refresh the solution explorer to reflect changes made outside of Visual Studio. Similarly, if I create a new file in the project directory (same directory as the other files in the project), it doesn't appear in the solution explorer. If I unload the project and reload the project, the new files is still not visible.
How can I refresh the solution explorer? My intention here is to better understand how Visual Studio organizes files in the solution explorer and how the organization relates to the actual file/directory structure in Windows.
After playing around with it for some time I realized that you can select the "Show All Files" button on the bar at the top of the Solution Explorer. This has a refresh button that works as expected (updates the Solution Explorer with the current state of the directory folder). It seems that files can be managed from this window and added/removed from the project in Visual Studio's default organization structure.

Sync Visual Studio folder/filename structure with file system structure/filenames

I've made a lot of changes (a.k.a refactoring) to my (big) visual studio solution and it appears now that vs solution structure is very different in visual studio from what it is on the disk and TFS.
Is there a way to make file system (and TFS) have the same folder names and file names as in visual studio solution with some tool or script/program/helper add-in?
This is the list of main issues:
- when I rename project visual studio does not rename folder where this project is located
- if I move project, file to different vs folder, it just happens in visual studio, but not on the disk
You can switch between logical or physical folders in the solution by clicking the "Show all files" icon (2nd top left icon in the solution pane). When not activated, you are viewing logical folders in the solution, drag and drop simply re arrange files virtually. When activated, you are viewing physical folders, drag and drop moves files on disk, using the source controller.
No there are no tools that can help you do this automatically.
There is a two step approach to solve it, made easier by installing two add-ons. I prefer to use the Team Foundation Power Tools and the Source Control Explorer Extensions.
From the Source Control Window inside Visual Studio:
Close the open solution in Visual Studio
open the Source Control window in TFS
Move the folders around to match the structure you prefer, with the mentioned add-ons you should be able to drag/drop and rename them more easily
Alternatively, do the changes on file system with the Team Foundation Power Tools explorer extensions installed:
Close the solution in Visual Studio
navigate to your workspace folder using Windows Explorer
use the TFS context menu on the folders to check-out/rename/move the items ans folders
Then re-load the solution in Visual Studio and:
Open the solution and see that a lot of projects don't load.
Highlight a project that couldn't be found
On the project properties window (ctrl-w, p) find the file path item and click the little [...] button to navigate to the new project file location for each project.
Rightclick the projects you've updated this way in the solution explorer and reload them
Rebuild your solution to verify all changes went as expected
Check-in your changes

How to add a new file association to Visual Studio?

(Windows XP, Visual Studio 2010 Express (Web Developer))
I would like to add various file types to open in Visual Studio that it does not open by default, namely .js, .html, .shtml, .css, etc.
I tried looking for UI inside Visual Studio to add new file types, but I couldn't find anything, so I tried the naive approach of right clicking on the file -> Open With -> Choose Program -> Browse -> c:\program files\Microsoft Visual Studio 10.0\Common7\IDE\VWDExpress.exe. This almost works, except it starts a new instance of the IDE rather than opening a new tab the way .cs files do.
I've tried to go registry diving, exported the association for .cs files, and changing it to point to .shtml (for example), but this still spawns new windows.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.shtml]
"Content Type"="text/plain"
"PerceivedType"="text"
#="VWDExpress.cs.10.0"
[HKEY_CLASSES_ROOT\.shtml\OpenWithProgids]
"VSTA.cs.9.0"=""
"VWDExpress.cs.9.0"=""
"VWDExpress.cs.10.0"=""
[HKEY_CLASSES_ROOT\.shtml\OpenWithProgids\Shared]
#="Shared key to keep this from being removed with install/uninstall of side-by-side components."
[HKEY_CLASSES_ROOT\.shtml\PersistentHandler]
#="{5e941d80-bf96-11cd-b579-08002b30bfeb}"
I strongly suspect that doing this is the wrong way to go about this, but I can't find a better solution. Is there one?
Ive had the same issue so downloaded VWD with SP1 along with VS.PHP 2.10. Right clicked on a .php file and chose 'open with vs.php 2.10', checked the checkbox on bottom which saves settings. Double clicking on a php file has been working since then. In order to be able to use it from a file manager like winscp i had to put 'explorer' as the editor executable. It works for my js html css and php files and opens them in the same VWD instance. Only pain may be that vs.php is to be paid for eventually and that you'd need to associate every extension you wish to work with.
After you use naive approach to associate file with VWDExpress.exe, find a command in registry and add /EDIT parameter. I don't know if this works for Express versions, but for full Visual Studio this opens file in already open Visual Studio instance.
Download Default Programs Editor and open.
In my case I was associating .php files to Visual Studio 11, and to do this I simply copied the settings for .cs files. I've noted all steps below.
FIle Type Settings > Context Menu
Search .php (or whatever association) - note you can multi-select
Click next
Click Add... under the list
Enter the following data:
Command name: Open
Program path: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" /dde
Now unfold the Advanced Settings, tick Use DDE Message, and click Edit. Add the following:
Message: Open("%1")
Application: VisualStudio.11.0
Topic: system
If you want to apply this to lots of files I suggest using the built in saving to registry option and creating a batch script with it.

Hidding source control files within Visual Studio's solution tree

We use Visual Studio 2008 and Surround SCM for source control. SCM drops files into each directory named ".MySCMServerInfo" which are user specific data files that shouldn't be checked into source control. They are similar to the .scc files dropped by Visual Source Safe. We also have several WAPs (Web Application Projects) that we develop. All these .MySCMServerInfo files show up in the solution tree and the Pending Checkins window when they should not. There has to be some way to force VS to ignore files of a given extension because it ignores .scc files. How do I get VS to ignore .MySCMServerInfo files within a WAP?
I have new information about this issue. Setting the hidden bit on .MySCMServerInfo file causes Surround SCM to loose track of the modification state for files. It starts thinking files are out-of-date when they are not, and it always attemps to get new versions.
Instead, set this registry key if you're using Visual Studio 2008:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Packages\
{8FF02D1A-C177-4ac8-A62F-88FC6EA65F57}\IgnorableFiles\.MySCMServerInfo]
Set this registry key if you're using Visual Studio 2005:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Packages\
{8FF02D1A-C177-4ac8-A62F-88FC6EA65F57}\IgnorableFiles\.MySCMServerInfo]
These will tell Visual Studio to not display .MySCMServerInfo files within the Solution tree and the Pending Checkins view.
Using the file system hidden bit should work.
Late Answer but hopefully useful to others.
I began experiencing this problem when using Visual Studio 2015 with the new ASP.Net 5 Project templates. (I presume this is because the new templates automatically include everything in the folder rather than only showing the things that are listed in the project file).
Showing these files in the Solution explorer change be prevented by right clicking the file and selecting "Hide from Solution Explorer" but this didn't prevent SCM from including them in the Pending Check-ins Window.
The correct way to deal with this problem is:
Select the file(s) in Solution Explorer
Select the File > Source Control > Exclude from Source Control
Reference
NOTE: Right Click in the Solution Explorer DOESN'T have this option.

How do you clear your MRU list in Visual Studio?

I want to clear the list of projects on the start page...how do I do this? I know I can track it down in the registry, but is there an approved route to go?
There is an MSDN article here which suggests that you just move the projects to a new directory.
However, as you mentioned, the list of projects is kept in the registry under this key:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\<version>\ProjectMRUList
and the list of recent files is kept in this key:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\<version>\FILEMRUList
Note For Visual Studio 2015:
The location has changed. You can check out this answer for details.
Some people have automated clearing this registry key with their own tools:
Visual Studio Most Recent Files Utility
Add-in for cleaning Visual Studio 2008 MRU Projects list
PowerCommands for Visual Studio 2008
Features
Clear Recent File List
Clear Recent Project List
Clear All Panes
Copy Path
Email CodeSnippet
Insert Guid Attribute
Show All Files
Undo Close
Collapse Projects
Copy Class
Paste Class
Copy References
Paste References
Copy As Project Reference
Edit Project File
Open Containing Folder
Open Command Prompt
Unload Projects
Reload Projects
Remove and Sort Usings
Extract Constant
Transform Templates
Close All
If you try opening up a project that can no longer be found, Visual Studio will prompt you for permission to remove it from the MRU list. So if you temporarily rename an appropriate top level folder to fake the projects' disappearance, you can get rid of the projects one by one.
In Visual Studio 2015 all the history lists (including search history, file MRU and project MRU) are now located at:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0\MRUItems
You will see a different GUID folder for each list, and a sub-folder called Items in each of them. Find the Items folder that contains the relevant list, and just delete its parent GUID folder.
Visual Studio will re-create the GUID folder together with a new Items child folder, next time it wants to add something to the list again.
I found the MRU editor from Code Project a great tool for that. No problems with it, and it works on 2003, 2005, and 2008.
Note: This answer is specific to Visual Studio 2010.
If you don't want to manually edit the registry, you can use PowerCommands for Visual Studio 2010.
PowerCommands 10.0 is a set of useful extensions for the Visual Studio
2010 adding additional functionality to various areas of the IDE.
The specific command for clearing the registry from the extension is:
Clear Recent Project List This command clears the Visual Studio recent project list. The Clear Recent Project List command brings up a
Clear File dialog which allows any or all recent projects to be
selected.
The PowerCommands can be installed with the Visual Studio extension manager: Tools > Extension Manager > Online Gallery: search for PowerCommands for Visual Studio 2010.
Try Recently Used Files: a free addin for Visual Studio that manages MRU files on a per-project basis:
Supported for VS 2010, 2012, 2013.
For Visual Studio 2012, 2013:
http://visualstudiogallery.msdn.microsoft.com/a61cbd1d-b5a2-490b-a6bb-f0ea3ecf214a
For Visual Studio 2010:
http://visualstudiogallery.msdn.microsoft.com/45283881-5a62-4dc1-8ffb-4cbc02709947
For Visual Studio 2013:
Open the Run dialog (Press Win + R)
type: regedit
navigate to: HKEY_CURRENT_USER > Software > Microsoft > VisualStudio
click 12.0 then the files will show up on the right side.
Look for the "LastLoadedSolution", right click then click Modify
change the value to 0.
This worked for me.
I'm not sure if this solution has been posted somewhere here, but if you have VS 2013 Update 5 you can open start page, and right click project below "Recent" list, and choose "Remove from list". I don't know how about other VS versions, maybe this feature is available.
I had this issue as applied to VS 2017 where you do not have any MRU items in the registry as in the previous versions. The solution was, on the other hand, simple: go to "Tools->Extensions and Updates" and install "Power Commands for Visual Studio". After they have been installed, your File menu will look as shown below.
Just click the menu item to clear the project MRU.

Resources