在代码中调用VS2012解决方案资源管理器命令

4

我正在尝试制作一个扩展程序,需要从代码中调用两个命令:

  • SolutionExplorer.SyncWithActiveDocument(将解决方案资源管理器与当前活动文档同步)
  • The Collapse All command in the Solution Explorer.(在解决方案资源管理器中折叠所有内容)

我找不到任何方法来调用这些功能。

请问有人知道如何实现吗?

1个回答

4
你尝试通过DTE执行命令了吗?
dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Activate(); 

// Sync with Active Document
dte.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument");

// Collapse All
int cmdidSolutionExplorerCollapseAll = 29;
Guid guidCMDSETID_StandardCommandSet11 = new Guid("D63DB1F0-404E-4B21-9648-CA8D99245EC3");
dte.Commands.Raise(guidCMDSETID_StandardCommandSet11.ToString("B"), cmdidSolutionExplorerCollapseAll, null, null);

如果您需要识别其他命令的ID,可以打开VSIP日志记录:

http://blogs.msdn.com/b/dr._ex/archive/2007/04/17/using-enablevsiplogging-to-identify-menus-and-commands-with-vs-2005-sp1.aspx

谢谢!你差不多已经为我写好了扩展。 - Chris McGrath
没问题,老兄。这基本上是从我的代码中复制粘贴而来的 :) - Dan Nolan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接