How can you make the file get added to the recent projects MRU list when programatically opening a solution in VS?

╄→гoц情女王★ 提交于 2019-12-02 18:45:56

问题


When a solution is programmatically opened in an add-in/extension (VS2012 in my case) using Solution.Open, the solution file is not added to the projects MRU (i.e. File->Recent Projects and Solutions menu) as it would be if you opened the solution using the File->Open->Project/Solution menu. Is there a way to force the file to be added? I've seen some references to manipulating the registry (e.g. HKCU\Software\Microsoft\VisualStudio\11.0\ProjectMRUList) but is there another way that doesn't assume the storage that VS uses and therefore would be less likely to break in the future? Perhaps a VS interface that might take care of it regardless of where the info might be stored. That would also allow me to ignore what the max # of mru items, avoiding errors in updating/re-numbering the existing items, etc. I found the IVsMRUItemsStore but if that is what I should use I'm unsure about what categoryGuid I would be using. From what I've seen it seems like this interface might be related to built in search functionality.

[Edit] Ok I've done some more digging. First, IVsMRUItemsStore seems unrelated to the project mru list since the Microsoft.VisualStudio.PlatformUI.MRUItemsStoreService seems to be empty even after showing the recent projects menu. Second, I've tried directly manipulating the registry but that doesn't work out well because VS doesn't know about the registry change and so the menu and its internal cache remain unchanged. If you subsequently open another project or solution using the Open Project dialog, the registry gets overwritten with the cached information plus the project/solution opened via the dialog. I would be ok with manipulating the registry if there was some way of notifying VS to re-read the registry info (without closing VS). I would also be happy if there were some other programmatic way of manipulating the recent projects list through VS' object model.

[Edit2] I've found that the View menu item in TFS' Source Control Explorer does exactly what I want. It will open a given solution, prompting if the solution needs to be converted (without closing the open documents) and adds the item to the MRU. The question now is how do I do the same thing in my extension/addin? I can't use their command (unless it takes a parameter) because the solution/project I'm opening is not in TFS.


回答1:


The TFS Source Control Explorer is simply calling IVsSolution.OpenSolutionFile, which adds the solution to the recent file lists. I suspect all you'll have to do is just use that instead of the EnvDTE method and you'll be good to go.



来源:https://stackoverflow.com/questions/16573115/how-can-you-make-the-file-get-added-to-the-recent-projects-mru-list-when-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!