在 VS 解决方案资源管理器中,如何在源文件子代码元素上扩展右键单击菜单 (class/method/field)

In VS Solution Explorer, how to extend right click menus on source files sub code elements (class/method/field)

我正在开发 Visual Studio 扩展 (VSIX)。

我需要在解决方案资源管理器中右键单击 class/methods/fields 项添加自定义右键单击菜单,可以在源文件项下找到:

在 .vsct 文件中,我已经以这种方式扩展了解决方案资源管理器 project/folder/source file/reference 右键菜单:

<CommandPlacement guid="guidNDepend_PackageCmdSet" id="grpSolutionExplorer" priority="0x100">
  <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE" />
</CommandPlacement>
<CommandPlacement guid="guidNDepend_PackageCmdSet" id="grpSolutionExplorer" priority="0x100">
  <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_PROJNODE" />
</CommandPlacement>
<CommandPlacement guid="guidNDepend_PackageCmdSet" id="grpSolutionExplorer" priority="0x100">
  <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_FOLDERNODE" />
</CommandPlacement>
<CommandPlacement guid="guidNDepend_PackageCmdSet" id="grpSolutionExplorer" priority="0x100">
  <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_REFERENCE" />
</CommandPlacement>    

我尝试了我找到的所有其他值但没有成功:

IDM_VS_CTXT_CODEWIN
IDM_VS_CTXT_XPROJ_MULTIITEM
IDM_VS_CTXT_XPROJ_PROJITEM
IDM_VS_CTXT_NOCOMMANDS
IDM_VS_CTXT_REFERENCEROOT

感谢您的帮助。

(请注意,在 QueryStatus() 处理程序被触发之前,我已经有了解决右键单击代码元素的棘手代码,从 IVsSelectionEvents.OnSelectionChanged() 调用)

参见:

Using EnableVSIPLogging to identify menus and commands with VS 2005 + SP1

和:

How to find Command GUID:ID pairs


谢谢 Carlos,我完成了这项工作 :) 让我们稍微解释一下。首先,如博客 post 中所述,我设置了注册码:

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio.0\General]
"EnableVSIPLogging"=dword:00000001

然后重新启动VS2013,在SlnExplorer Window 中按住Ctrl+SHIFT 并右键单击文件内容class。我明白了:

Guid 是 guidSHLMainMenu,但我需要从值 1842(十六进制的 0x0732)中获取命令 ID。我用谷歌搜索了一下,发现 this answer。我安装了 VS2013 SDK。我查找了头文件 vsshlids.h 的位置。它位于:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Common\Inc

在这个目录中,我搜索了任何包含 732 的文本文件。我发现

#define IDM_VS_CTXT_PROJWIN_FILECONTENTS            0x732  // Context menu for GraphNode items in the Solution Explorer

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Common\Inc\vsshlids.h

因此,我正在寻找的名称是 IDM_VS_CTXT_PROJWIN_FILECONTENTS,确实,有了这个值,它就像一个魅力;谢谢卡洛斯!