locked
VSSDK Howto Fill MRUList into MRUListBox RRS feed

  • Question

  • I have an MruListBox container in a xaml and I want to fill them with the MruList of the latest used projects in VS2019.

    The code I use in the XAML is:

    <vs:MruListBox
        ItemsSource="{Binding Path=Items}"
        AutomationProperties.AutomationId="MruList" FontFamily="Segoe UI"/>

    Now how can I get the MruList, which I want to set to the property Items so that the list is shown.

    I tried to get the MruList with the command

    IVsWebURLMRU weburlmru =this.GetService(typeof(SVsWebURLMRU)) as IVsWebURLMRU;

    and also with

    IVsWebURLMRU weburlmru =Package.GetGlobalService(typeof(SVsWebURLMRU)) as IVsWebURLMRU;

    and then with

    weburlmru.GetURLArray(out object list);

    but the array is empty.

    I also tried to use an example by Microsoft, where a menu with the last used items are shown, but I think this example was used in an older VisualStudio version. I need them for VS 2019.

    Regards, Tom


    Monday, July 27, 2020 4:06 PM

Answers

  • Hi TomGo1971,

    >>Now I should find out howto access to a private registry file, to find the right GUID for the MRU list and how I can read them.

    You could use External Settings Manager to get MRU list from registry file. For more information, please refer to: https://stackoverflow.com/a/42819130/11557747 

    By the way, I tried to follow 'Add a most recently used list to a submenu', and then add related codes into InitializeMRUList method, which is like:

    private void InitializeMRUList()
            {
                if (null == this.mruList)
                {
                    this.mruList = new ArrayList();
                    if (null != this.mruList)
                    {
                        //Use ExternalSettingsManager
                        ExternalSettingsManager ext = ExternalSettingsManager.CreateForApplication(@"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe");
                        SettingsStore store = ext.GetReadOnlySettingsStore(SettingsScope.UserSettings);
                        foreach (string name in store.GetPropertyNames(@"MRUItems\{a9c4a31f-f9cb-47a9-abc0-49ce82d0b3ac}\Items"))
                        {
                            string value = store.GetString(@"MRUItems\{a9c4a31f-f9cb-47a9-abc0-49ce82d0b3ac}\Items", name);
                            string[] subValue = value.Split('|');
                            this.mruList.Add(subValue[0]);
                        }
                    }
                }
            }

    And the latest used project will be displayed in sub menu. You can download the sample from one drive.

    Best Regards,

    Dylan


    "Visual Studio Integrate" forum will be migrating to a new home on  Microsoft Q&A!

    We invite you to post new questions in the "Visual Studio Integrate" forum’s new home on  Microsoft Q&A!

    For more information, please refer to the sticky post<Link>.



    Wednesday, August 5, 2020 7:19 AM
  • Hi Dylan

    Thanks for your reply and the code. It works.
    I made it a little bit common to avoid constants and use VS settings:

    string vsExePath = AppDomain.CurrentDomain.BaseDirectory + "devenv.exe";
    string mruPath = @"MRUItems\{" + VSConstants.MruList.Projects + @"}\Items";
    
    ExternalSettingsManager ext = ExternalSettingsManager.CreateForApplication(vsExePath);
    SettingsStore store = ext.GetReadOnlySettingsStore(SettingsScope.UserSettings);
    mruList = new List<string>();
    foreach (string name in store.GetPropertyNames(mruPath))
    {
        string value = store.GetString(mruPath, name);
        string[] subValue = value.Split('|');
        mruList.Add(subValue[0]);
    }
    

    The Guid can be taken from

    VSConstants.MruList.Projects

    I also found another solution using the service provider like this:

    Guid guid = VSConstants.MruList.Projects;
    
    IVsMRUItemsStore mruobj = await ServiceProvider.GetGlobalServiceAsync(typeof(SVsMRUItemsStore)) as IVsMRUItemsStore;
    string[] mruItems = new string[10];
    uint itemCount = mru.GetMRUItems(ref guid, "", 10, mruItems);
    mruList = new List<string>();
    for (int i = 0; i < itemCount; i++)
    {
        string[] subValue = mruItems[i].Split('|');
        mruList.Add(subValue[0]);
    }

    Please note, that the order of the items are in reversed manner, means using the external settings manager, the list starts from the oldest to the latest solution, and using the service provider, the list starts with latest solution first and goes to the oldest solution at the end.

    Keep aware, using the solution manager takes a little time to get the global service, which results in a delay till the list is shown.

    Thursday, August 6, 2020 2:15 PM

All replies

  • Hi TomGo1971,

    Please try to follow this document: Add a most recently used list to a submenu 

    BTW, I find a extension about MRU: start-page-plus, maybe it could help you.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, July 28, 2020 8:43 AM
  • Hi Dylan

    Thanks for your reply.

    I already tried the
    "Add a most recently used list to a submenu"
    tutorial, but it didn't work in VisualStudio 2019.
    The recent projects did not shown in the submenu.

    But the extension seems to be promising. I will try them as soon as possible.

    Kind regards,
    Tom

    Tuesday, July 28, 2020 11:36 AM
  • Hi TomGo1971,

    Does this extension help you? If you have any update, please feel free to contact us.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, August 3, 2020 9:06 AM
  • Hi Dylan

    Unfortunately this extension does not help. It is not working in the newest Version of Visual Studio 2019.
    Starting the project in a VSIX and opening the StartPage+, the exception "could not find file or assembly CommonServiceLocator, ... , or a dependency"

    I don't know the problem. There is no reference to CommonServiceLocator in the projects.

    If I download the VSIX of this extension and install them in Visual Studio, the extension crashes in newer versions.

    I had a look into code. There is a recentItemDataService. This fetches the list from the registry key 'ApplicationPrivateSettings/_metadata/baselines/CodeContainers', but such a key is only existing for older VisualStudio Versions like 14.0

    Kind regards,
    Tom

    Tuesday, August 4, 2020 3:13 PM
  • I found out, that since Visual Studio 2017, the MRU list is stored in a private registry file.
    Explained is here: https://github.com/Microsoft/VSProjectSystem/blob/master/doc/overview/examine_registry.md

    Now I should find out howto access to a private registry file, to find the right GUID for the MRU list and how I can read them.

    Do you have a tip ?

    Tuesday, August 4, 2020 3:48 PM
  • Hi TomGo1971,

    >>Now I should find out howto access to a private registry file, to find the right GUID for the MRU list and how I can read them.

    You could use External Settings Manager to get MRU list from registry file. For more information, please refer to: https://stackoverflow.com/a/42819130/11557747 

    By the way, I tried to follow 'Add a most recently used list to a submenu', and then add related codes into InitializeMRUList method, which is like:

    private void InitializeMRUList()
            {
                if (null == this.mruList)
                {
                    this.mruList = new ArrayList();
                    if (null != this.mruList)
                    {
                        //Use ExternalSettingsManager
                        ExternalSettingsManager ext = ExternalSettingsManager.CreateForApplication(@"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe");
                        SettingsStore store = ext.GetReadOnlySettingsStore(SettingsScope.UserSettings);
                        foreach (string name in store.GetPropertyNames(@"MRUItems\{a9c4a31f-f9cb-47a9-abc0-49ce82d0b3ac}\Items"))
                        {
                            string value = store.GetString(@"MRUItems\{a9c4a31f-f9cb-47a9-abc0-49ce82d0b3ac}\Items", name);
                            string[] subValue = value.Split('|');
                            this.mruList.Add(subValue[0]);
                        }
                    }
                }
            }

    And the latest used project will be displayed in sub menu. You can download the sample from one drive.

    Best Regards,

    Dylan


    "Visual Studio Integrate" forum will be migrating to a new home on  Microsoft Q&A!

    We invite you to post new questions in the "Visual Studio Integrate" forum’s new home on  Microsoft Q&A!

    For more information, please refer to the sticky post<Link>.



    Wednesday, August 5, 2020 7:19 AM
  • Hi Dylan

    Thanks for your reply and the code. It works.
    I made it a little bit common to avoid constants and use VS settings:

    string vsExePath = AppDomain.CurrentDomain.BaseDirectory + "devenv.exe";
    string mruPath = @"MRUItems\{" + VSConstants.MruList.Projects + @"}\Items";
    
    ExternalSettingsManager ext = ExternalSettingsManager.CreateForApplication(vsExePath);
    SettingsStore store = ext.GetReadOnlySettingsStore(SettingsScope.UserSettings);
    mruList = new List<string>();
    foreach (string name in store.GetPropertyNames(mruPath))
    {
        string value = store.GetString(mruPath, name);
        string[] subValue = value.Split('|');
        mruList.Add(subValue[0]);
    }
    

    The Guid can be taken from

    VSConstants.MruList.Projects

    I also found another solution using the service provider like this:

    Guid guid = VSConstants.MruList.Projects;
    
    IVsMRUItemsStore mruobj = await ServiceProvider.GetGlobalServiceAsync(typeof(SVsMRUItemsStore)) as IVsMRUItemsStore;
    string[] mruItems = new string[10];
    uint itemCount = mru.GetMRUItems(ref guid, "", 10, mruItems);
    mruList = new List<string>();
    for (int i = 0; i < itemCount; i++)
    {
        string[] subValue = mruItems[i].Split('|');
        mruList.Add(subValue[0]);
    }

    Please note, that the order of the items are in reversed manner, means using the external settings manager, the list starts from the oldest to the latest solution, and using the service provider, the list starts with latest solution first and goes to the oldest solution at the end.

    Keep aware, using the solution manager takes a little time to get the global service, which results in a delay till the list is shown.

    Thursday, August 6, 2020 2:15 PM
  • Hi TomGo1971,

    I'm glad to hear that the reply is helpful for you. We suggest you could mark the proposed replies as answers. It will be beneficial to other community members who has similar question. 

    By the way, if you have other questions about VS extension in the future, please feel free to contact us. And this forum is being migrated to a new home on Microsoft Q&A, we suggest you could post the question there.

    Best Regards,

    Dylan


    "Visual Studio Integrate" forum will be migrating to a new home on  Microsoft Q&A!

    We invite you to post new questions in the "Visual Studio Integrate" forum’s new home on  Microsoft Q&A!

    For more information, please refer to the sticky post<Link>.


    Friday, August 7, 2020 6:06 AM