Click here to Skip to main content
Click here to Skip to main content
Go to top

Visual Studio MRU Projects Editor

, 15 Oct 2010
Rate this:
Please Sign up or sign in to vote.
An application that edits the Visual Studio MRU projects list.

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)

Share

About the Author

Mokdes Hamid
Software Developer (Senior)
Canada Canada
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
 

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 1 PinmemberAlberto Molero15-Oct-10 4:11 
GeneralRe: My vote of 1 PinmemberMokdes Hamid15-Oct-10 5:03 
GeneralRe: My vote of 1 PinmemberMLansdaal15-Oct-10 10:11 
Generalsimilar post... PinmemberAlberto Molero15-Oct-10 4:09 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 15 Oct 2010
Article Copyright 2010 by Mokdes Hamid
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid