Click here to Skip to main content
15,881,709 members
Articles / Programming Languages / C#
Article

Visual Studio Project MRU List Editor

Rate me:
Please Sign up or sign in to vote.
4.56/5 (15 votes)
28 Jun 20053 min read 74.3K   456   26   11
A tool for editing the "Start Page" Recent Project List in Visual Studio .NET.

Image 1

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.

C#
using Microsoft.Win32;

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

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

C#
/// <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:

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


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralLatest version Pin
peterchen6-Apr-07 0:26
peterchen6-Apr-07 0:26 
Generalstart page Pin
Moekie3-Oct-06 0:46
Moekie3-Oct-06 0:46 
GeneralModified the MRU program Pin
Achintya Jha12-Sep-06 10:13
Achintya Jha12-Sep-06 10:13 
GeneralRe: Modified the MRU program Pin
J. Beach12-Sep-06 16:05
J. Beach12-Sep-06 16:05 
GeneralRe: Modified the MRU program Pin
Achintya Jha13-Sep-06 4:27
Achintya Jha13-Sep-06 4:27 
GeneralWack them projects away Pin
IC1826-Jun-06 10:18
IC1826-Jun-06 10:18 
QuestionThe name 'm_ProjectMRUKey' does not exist in the current context Pin
snowlin12-Jun-06 11:41
snowlin12-Jun-06 11:41 
AnswerRe: The name 'm_ProjectMRUKey' does not exist in the current context [modified] Pin
Josh Beach12-Jun-06 17:43
Josh Beach12-Jun-06 17:43 
GeneralAt last, success .... Pin
Khurram Hassan12-Apr-06 20:16
Khurram Hassan12-Apr-06 20:16 
GeneralA wonderful tool! Pin
Troye Stonich27-Dec-05 6:46
Troye Stonich27-Dec-05 6:46 
GeneralList ordered by dates Pin
ChrisFrazier7-Jul-05 8:56
ChrisFrazier7-Jul-05 8:56 
Nice one!

I noticed that no matter what order I put the files in using it, they were indexed by the last date the sln file was changed (according to explorer (in 2003)). To get my most active project to the top, I just opened the .sln in textpad and "touched" it - gave it a space and immediately removed it to change the last modified date to today.

Just FYI.

-Christopher
ASP.NET MVP | AspInsider
http://www.chrisfrazier.net/blog

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.