Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Visual Studio Project MRU List Editor

0.00/5 (No votes)
28 Jun 2005 1  
A tool for editing the "Start Page" Recent Project List in Visual Studio .NET.

Introduction

Anyone who has used Visual Studio to create more than one project or solution has used the "Start Page" to see the most recently used (MRU) projects or solutions. If you are like me, you often have more than one Visual Studio instance opened and have been frustrated by the fact that the list never seems to be "right". In addition I find myself often creating "temporary" projects to test a new idea and don't want to see these projects on my MRU Project List.

I have seen two articles on CodeProject discussing the "Start Page", but neither gave me an easy way to edit or maintain this list. The Stagner article speaks of maintaining the list by editing the registry, which in the end is all my tool does, but I wanted an interface to maintain the list.

Background

Visual Studio stores the MRU Projects in the registry under the path 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

There is a string value for each recent file named File1, File2, File3, etc. with a value of the full path to the file. Visual Studio updates this list on close, which is the root of some of my problems. Multiple versions of Visual Studio do not communicate about their open projects, nor do they read the current state of the registry and attempt to merge them. On close, Studio clears this key and re-writes out the list as it knows it. My scenario is as follows:

  • Open a copy of Visual Studio and create Project 1
  • Open a second copy of Visual Studio and create Project 2
  • Close the second copy of Visual Studio. Project 2 is written out to the Registry.
  • Close the first copy of Visual Studio. The Key is cleared and Project 1 is written out to the Registry.
  • Open Visual Studio again to find that it "forgot" about Project 2.

Important Note

Since Visual Studio clears and rewrites the list on close, you must have all instances of Visual Studio before using this tool.

Using the code

There is no real magic in this code; one listbox, six buttons and some Registry code.

Since we are using the Registry, we need to include the Microsoft.Win32 namespace.

    using Microsoft.Win32;

On the form load we open the key in a writable mode:

    private void MainForm_Load(object sender, System.EventArgs e) {
        // Open a writable RegKey

        m_ProjectMRUKey = Registry.CurrentUser.OpenSubKey(PROJECT_MRU_PATH, true);
    }

Loading and daving methods:

    /// <SUMMARY>

    /// Loads (Reads) Registry Values into ListBox

    /// </SUMMARY>

    private void btnLoad_Click(object sender, System.EventArgs e) {
        lstBoxMain.Items.Clear();
        foreach (string key in m_ProjectMRUKey.GetValueNames()) {
            lstBoxMain.Items.Add(m_ProjectMRUKey.GetValue(key));
        }
    }

    /// <SUMMARY>

    /// Save (Writes) Registry Values from ListBox

    /// </SUMMARY>

    private void btnSave_Click(object sender, System.EventArgs e) {
        foreach (string key in m_ProjectMRUKey.GetValueNames())
            m_ProjectMRUKey.DeleteValue(key);

        for(int i=0; i < lstBoxMain.Items.Count; ++i) {
            m_ProjectMRUKey.SetValue("File" + (i+1), lstBoxMain.Items[i]);
        }
        //Flush the object to force it to write the files to the Registry

        m_ProjectMRUKey.Flush();
    }

Form closing - Close the Registry key:

    private void MainForm_Closed(object sender, System.EventArgs e) {
        //Close and flush the registry value on close

        m_ProjectMRUKey.Close();
    }

The rest of the code deals with maintaining the ListBox by removing the selected item, or moving it up or down in order. There is also an Add button to create a new item in the list for unknown projects. Note that the OpenFileDialog called in the Add function only filters to look for a small subset of the total Visual Studio supported file types. It was enough to suit my needs and I added an "All Files" filter as a catch-all.

Final Thoughts

As the radio clich� goes, "I'm a long time listener first time caller to CodeProject". I hope this simple article is useful to those who take the time to read it. I use this tool all the time and have found it very helpful. Depending on how my experience with this article goes, I will hopefully be back to lend more tips and tricks to the coding community. I look forward to your comments and / or questions.

History

  • Version 1.0: Initial release.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here