Click here to Skip to main content
Click here to Skip to main content

Visual Studio MRU Projects Editor

By , 15 Oct 2010
 

Introduction

So often when learning about a specific API or a new technology, I create many small solutions, and by time the list of solutions grows outside what Visual Studio can display in its start page, soon the list of most recently used solutions becomes not very useful since it displays lots of solutions that I do not really use any more.

Since editing the list form Visual Studio is not possible [at least I do not know about any option or dialog from within VS that lets us edit this list or clear it altogether], I have created this little application to clear things out.

Background

I was looking in CodeProject for an application that does what I was looking to, and I found this article: Visual Studio Project MRU List Editor that explains where Visual Studio saves the MRU list. But because I had more than a version of Visual Studio on my machine, I have created this app to handle different versions.

Here is the application at runtime:

Choose your Visual Studio version:

Image1.PNG

Visual Studio 2005 MRU displayed:

Image2.PNG

Navigating the MRU list:

Image3.PNG

Edit an item:

Image5.PNG

Item updated:

Image6.PNG

Important Note

Visual Studio instances do rewrite the list when they are closed; to effectively clear the MRU list, all instances of the target Visual Studio should be closed.

Using the Code

All it takes to build this application is to read the Registry entries and rewrite them.

Visual Studio stores the MRU list in the following registry location: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\XX\ProjectMRUList, where XX is the version number of Visual Studio.

  • Visual Studio 2002 - 7.0
  • Visual Studio 2003 - 7.1
  • Visual Studio 2005 - 8.0
  • Visual Studio 2008 - 9.0
  • Visual Studio 2010 - 10.0

There is a class called Util that stores these values in a Hashtable:

internal static class Utils
{
    private static Hashtable visualStudioVersions = new Hashtable();
    private static string commonPath = @"Software\Microsoft\VisualStudio";
    private static string projectMRUList = "ProjectMRUList";
    public static  Hashtable VisualStudioVersions
    {
        get { return visualStudioVersions; }
    }
    // Intializes et sets supported versions.
    static Utils()
    {
        visualStudioVersions.Add("7.0", "Visual Studio 2002");
        visualStudioVersions.Add("7.1", "Visual Studio 2003");
        visualStudioVersions.Add("8.0", "Visual Studio 2005");
        visualStudioVersions.Add("9.0", "Visual Studio 2008");
        visualStudioVersions.Add("10.0", "Visual Studio 2010");
    }
    /// Opens MRU sub keys and retreives installed Visual Studio Versions.
    public static List<VisualStudioVersion> GetInstalledVersions()
    {
        List<VisualStudioVersion> installedVersions = null;
        RegistryKey visualStudio = null;
        try
        {
            visualStudio = Registry.CurrentUser.OpenSubKey(commonPath);
            if (visualStudio != null)
            {
                installedVersions = new List<VisualStudioVersion>();
                foreach (string key in visualStudio.GetSubKeyNames())
                {
                    if (visualStudioVersions.ContainsKey(key))
                    {
                        installedVersions.Add(new VisualStudioVersion(key, 
                            (string)visualStudioVersions[key]));
                    }
                }
            }
        }
        catch 
        {
        }
        finally
        {
            if (visualStudio != null)
                visualStudio.Close();
        }
        return installedVersions;
    }
    
    /// Returns the list of Recently used solutions.
    public static List<string> GetMRUList(VisualStudioVersion version)
    {
        List<string> mruList = null;
        RegistryKey mruRegistryKey = null;
        try
        {
            if (version != null)
            {
                mruRegistryKey = Registry.CurrentUser.OpenSubKey(
                    String.Format(@"{0}\{1}\{2}",
                    commonPath, version.Version, projectMRUList));
                if(mruRegistryKey != null)
                {
                    mruList = new List<string>();
                    string[] fileKeys = mruRegistryKey.GetValueNames();
                    if (fileKeys != null && fileKeys.Length > 0)
                    {
                        foreach (string key in fileKeys)
                        {
                            mruList.Add((string)mruRegistryKey.GetValue(key));
                        }
                    }
                }
            }
        }
        catch 
        {
        }
        finally
        {
            if (mruRegistryKey != null)
                mruRegistryKey.Close();
        }
        return mruList;
    }

    /// Saves and Update MRU registry list
    public static void SaveMruList(VisualStudioVersion version, 
                  List<VisualStudioSolution> solutions)
    {
        RegistryKey mruRegistryKey = null;
        try
        {
            if (solutions != null && version != null)
            {
                mruRegistryKey =
                    Registry.CurrentUser.OpenSubKey(String.Format(@"{0}\{1}\{2}",
                    commonPath, version.Version, projectMRUList), true);
                if (mruRegistryKey != null)
                {
                    foreach (string key in mruRegistryKey.GetValueNames())
                    {
                        mruRegistryKey.DeleteValue(key);
                    }
                    for (int i = 0; i < solutions.Count; i++)
                    {
                        mruRegistryKey.SetValue("File" + 
                          (i + 1).ToString(), solutions[i].SolutionPath);
                    }
                }
            }
        }
        catch
        {
        }
        finally
        {
            if (mruRegistryKey != null)
                mruRegistryKey.Close();
        }
    }

    /// Holds the version number and description about VS.
    internal class VisualStudioVersion
    {
        public VisualStudioVersion(string version, string description)
        {
            this.version = version;
            this.description = description;
        }
        private string version;
        public string Version
        {
            get { return version; }
            set { version = value; }
        }
        private string description;
        public string Description
        {
            get { return description; }
            set { description = value; }
        }
    }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Mokdes Hamid
Software Developer (Senior)
Canada Canada
Member
I've been working with .Net since 2006, I use C# as my favorite programming language and I have a strong knowledge about .Net frameworks, Windows and Web development.
 
I'm interested in a broad range of technologies that include ASP.net, ADO.Net, WinForms, WPF, Silverlight as well as Best practices in development and design patterns.
 
I hold currently the following certifications:
MCTS: .NET Framework 2.0 Web Applications
MCTS: .NET Framework 2.0 Windows Applications
MCTS: .NET Framework 2.0 Distributed Applications
MCPD: Designing and Developing Enterprise Applications by Using the Microsoft .NET
 
For more posts:
C# and Windows Form Programming
 
Walkthrough on how to create a Control Extender in C#
 
Control Anchoring Class

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 1memberAlberto Molero15 Oct '10 - 4:11 
the structure is similar that my post...if this code is based in my code...i don't have any mention in this post...
GeneralRe: My vote of 1memberMokdes Hamid15 Oct '10 - 5:03 
I have not had the chance to see your post when I searched for this topic, but I did found the following one that I have mentioned in the Background section of the article Wink | ;)
Visual Studio Project MRU List Editor
Mokdes Senior .Net Developer

GeneralRe: My vote of 1memberMLansdaal15 Oct '10 - 10:11 
Searching to determine what's out there can be hit or miss at times. However, a quick Code Project search of "Visual Studio MRU" gave up hits on the first search results page that shows that the capability has been previously developed and written about. I hate to see duplicated work but sometimes there are reasons to duplicate - such as wanting to learn how to do something or not liking some aspect of the existing work and to correct the perceived limitation/deficiency. For example, in http://www.codeproject.com/KB/cs/VSProjectListEditorIII.aspx, it states:
 
I really like the app, but I had a few niggles so I made some changes of my own:
 
It now supports Visual Studio 2008 
* The default Studio version selected in the drop-down box will be the newest, rather than the oldest 
* The buttons have ToolTips 
* It doesn't list Visual Studio versions that you don't have installed 
* Better-looking buttons 
* Re-named some of the buttons and changed the layout a bit 
* Added an installer project 
* A few other tweaks and fiddles because I was bored 
 
Anything new or better in your implementation?
Generalsimilar post...memberAlberto Molero15 Oct '10 - 4:09 
please if you are based your code in other, please mention the others author's... but...i think that it's very similar that my post: My Post

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 15 Oct 2010
Article Copyright 2010 by Mokdes Hamid
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid