在 VS 中以编程方式打开解决方案时,如何将文件添加到最近的项目 MRU 列表中? [英] How can you make the file get added to the recent projects MRU list when programatically opening a solution in VS?

本文介绍了在 VS 中以编程方式打开解决方案时,如何将文件添加到最近的项目 MRU 列表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 Solution.Open,解决方案文件不会添加到项目 MRU(即文件->最近的项目和解决方案菜单)中文件->打开->项目/解决方案菜单.有没有办法强制添加文件?我已经看到了一些操作注册表的参考资料(例如 HKCU\Software\Microsoft\VisualStudio\11.0\ProjectMRUList)但是还有另一种方法不假设 VS 使用的存储,因此会是将来不太可能打破?也许一个 VS 接口可以处理它,而不管信息可能存储在哪里.这也可以让我忽略 mru 项目的最大数量,避免在更新/重新编号现有项目时出现错误等.我找到了 IVsMRUItemsStore 但如果这是我应该使用的我'我不确定我会使用什么 categoryGuid.从我所见,此界面似乎与内置搜索功能有关.

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.

[编辑] 好的,我已经做了更多的挖掘.首先,IVsMRUItemsStore 似乎 与项目 mru 列表无关,因为即使在显示最近的项目菜单之后 Microsoft.VisualStudio.PlatformUI.MRUItemsStoreService 似乎还是空的.其次,我尝试过直接操作注册表,但效果不佳,因为 VS 不知道注册表更改,因此菜单及其内部缓存保持不变.如果您随后使用打开项目"对话框打开另一个项目或解决方案,则注册表将被缓存信息以及通过该对话框打开的项目/解决方案覆盖.如果有某种方式通知 VS 重新读取注册表信息(不关闭 VS),我可以操作注册表.如果有其他一些编程方式可以通过 VS 的对象模型操作最近的项目列表,我也会很高兴.

[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] 我发现 TFS 的源代码管理资源管理器中的查看菜单项完全符合我的要求.它将打开给定的解决方案,提示是否需要转换解决方案(不关闭打开的文档)并将项目添加到 MRU.现在的问题是我如何在我的扩展/插件中做同样的事情?我无法使用他们的命令(除非它带有参数),因为我打开的解决方案/项目不在 TFS 中.

[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.

推荐答案

TFS 源代码管理资源管理器只是调用 IVsSolution.OpenSolutionFile,将解决方案添加到最近的文件列表中.我怀疑您所要做的就是使用它而不是 EnvDTE 方法,您就可以开始使用了.

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.

这篇关于在 VS 中以编程方式打开解决方案时,如何将文件添加到最近的项目 MRU 列表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆