0

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.

AndrewS
  • 6,054
  • 24
  • 31

1 Answers1

3

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.

Jason Malinowski
  • 18,148
  • 1
  • 38
  • 55
  • Thanks for the reply. I actually use the EnvDTE because it won't close the open documents (e.g. if I have a workitem open or a workitem query list). When I use OpenSolutionFile (which I have to if I want VS to convert the solution) it closes the open files. Interestingly if I open a solution from the source control explorer those windows don't close. Do you happen to know what flags source control explorer uses with OpenSolutionFile or something else it might be doing to affect that? – AndrewS May 16 '13 at 13:55
  • Well for now I've had to hack it by replacing/setting the viewhelper of the documents I want to keep open with my own IVsWindowFrameNotify3 implementation and aborting the close but I'm not happy with it so if there is some additional flags or other way please let me know. Thx – AndrewS May 16 '13 at 21:28
  • Dropping a breakpoint on OpenSolutionFile, it appears TFS is passing the SLNOPENOPT_AddToCurrent, but I'm not sure what the controls exactly. There's also some logic I don't understand controlling when it does or doesn't pass it. The code isn't clear at all. :-( – Jason Malinowski May 23 '13 at 03:04
  • I misunderstood the point of AddToCurrent and must not have tried that because that gets me close enough to what I want. Thanks for the info. – AndrewS May 23 '13 at 14:05
  • Yeah, AddToCurrent seems poorly documented. :-) – Jason Malinowski May 23 '13 at 15:43
  • Thanks for the hint with IVSSolution.OpenSolutionFile. Is there a similar method that works with project files? I tried OpenSolutionFile and CreateProject but this didn't work as expected. OpenSolutionFile does nothing, CreateProject opens the project, but doesn't update the MRU list. – Danielku15 Jun 29 '15 at 17:48