Click here to Skip to main content
15,885,188 members
Articles / Desktop Programming / Windows Forms

Visual Studio MRU Projects Editor

Rate me:
Please Sign up or sign in to vote.
3.00/5 (2 votes)
15 Oct 2010CPOL2 min read 17.9K   169   3   4
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:

C#
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)


Written By
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

Walkthrough on how to create a Control Extender in C#

Control Anchoring Class

Comments and Discussions

 
GeneralMy vote of 1 Pin
Alberto M.15-Oct-10 4:11
Alberto M.15-Oct-10 4:11 
GeneralRe: My vote of 1 Pin
Mokdes Hamid15-Oct-10 5:03
Mokdes Hamid15-Oct-10 5:03 
GeneralRe: My vote of 1 Pin
MLansdaal15-Oct-10 10:11
MLansdaal15-Oct-10 10:11 
Generalsimilar post... Pin
Alberto M.15-Oct-10 4:09
Alberto M.15-Oct-10 4:09 

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

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