【问题标题】:Calling VS2012 Solution Explorer Commands in code在代码中调用 VS2012 解决方案资源管理器命令
【发布时间】:2023-03-12 02:21:01
【问题描述】:

我正在尝试进行扩展,我需要从代码中调用两个命令...

  • SolutionExplorer.SyncWithActiveDocument
  • 解决方案资源管理器中的全部折叠命令。

无论如何我都找不到调用这些函数的方法。

有人知道怎么做吗?

【问题讨论】:

    标签: visual-studio visual-studio-2012 visual-studio-extensions


    【解决方案1】:

    您是否尝试过通过 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

    【讨论】:

    • 谢谢!你几乎为我写了我的扩展。
    • 别担心,伙计,这或多或少是我自己的代码的复制+粘贴:)
    猜你喜欢
    • 2014-03-21
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 2014-02-04
    • 1970-01-01
    • 2011-02-04
    • 2020-11-26
    • 1970-01-01
    相关资源
    最近更新 更多