追加项目添加解决方案 - 或项目节点的菜单在Solution Explorer项目、节点、菜单、解决方案

2023-09-03 04:36:39 作者:小乖买糖吃

我如何添加一个子菜单添加菜单项时,右键点击一个Visual Studio解决方案资源管理器?

How can I add a sub menu for the Add menu item when right click on a visual studio solution explorer?

我要补充,这将显示n右单击Visual Studio解决方案一个子菜单项移动到该菜单中添加选项。

I have to add a single sub menu item which will be displayed n right clicking the visual studio solution and move to the Add option in that menu.

我使用.vsct(VS包)尝试。请帮我宝贵的建议

I am trying using .vsct (vs package). Please help me with valuable suggestions

推荐答案

当然,也有similiar的问题,但是这似乎是一个特例......

Of course, there are similiar questions, but this seems to be a special case...

在一般情况下,你需要知道你要扩展的menu's命令 - 和包装标识。我通常做这个通过启用如本文由注册表中的 EnableVSIPLogging 选项: http://blogs.msdn.com/b/dr._ex/archive/2007/04/17/using-enablevsiplogging-to-identify-menus-and-commands-with-vs-2005-sp1.aspx.该 EnableVSIPLogging 选项中引入了Visual Studio 2005中,但在任何新版本仍然有效。

In general, you need to know the menu´s command- and package id that you want to extend. I usually do this by enabling the EnableVSIPLogging option in the registry as described by this article: http://blogs.msdn.com/b/dr._ex/archive/2007/04/17/using-enablevsiplogging-to-identify-menus-and-commands-with-vs-2005-sp1.aspx. The EnableVSIPLogging option was introduced with Visual Studio 2005, but still works in any newer version.

一旦 EnableVSIPLogging 选项已启用,您可以通过点击菜单项显示想要的信息,而$(或者说是互联与命令任何其他UI元素) p $ pssing 控制 + 移。这将显示包含包GUID和命令/菜单ID的消息框; 控制 + C 副本显示菜单 - 或Command数据复制到剪贴板,顺便说一句。如果you're感兴趣的菜单数据(如遇it'sa上下文菜单中,preSS 控制 + 移徘徊在项目之前)。

Once the EnableVSIPLogging option is enabled, you can display the wanted information by clicking on a menu item (or any other UI element that is interconnected with a command) while pressing Ctrl+Shift. This will show a message box containing the package guid and command/menu id; Ctrl+C copies the shown menu- or command- data to the clipboard, btw. If you´re interested in menu data (in case it´s a context menu, press Ctrl+Shift before hovering the item).

这就是我得到了我的机器上......

This is what I got on my machine...

---------------------------
VSDebug Message
---------------------------
Menu data:
Guid = {D309F791-903F-11D0-9EFC-00A0C911004F}
GuidID = 4
CmdID = 850
Type = 0x00000100
Flags = 0x00000000
NameLoc = A&dd
---------------------------
OK   
---------------------------

菜单信息可以比创作的 VSCT 文件中使用;这个问题可能是你的兴趣:Using VSX你如何创建一个子菜单,命令?

The menu information can than be used in authoring your VSCT file; this question might be of your interest: Using vsx how do you create a sub menu with commands?

在阅读其他question's答案,你可能会想知道这些人想通了命令的GUID ...这些名称是由定义的名称 vsshlids.h 头文件,它包含在Visual Studio的SDK。因此,对于GUID如上图所示,我们发现...

While reading the other question´s answer, you may wonder how these guys figured the names for the command guids... those names are defined by the vsshlids.h header file, which is included with the Visual Studio SDK. So, for the guid shown above we find...

// Guid for Shell's group and menu ids
DEFINE_GUID (guidSHLMainMenu,
    0xd309f791, 0x903f, 0x11d0, 0x9e, 0xfc, 0x00, 0xa0, 0xc9, 0x11, 0x00, 0x4f);

我们可以使用 guidSHLMainMenu 为组定义...

We can use guidSHLMainMenu for the group definition...

<Group guid="your-command-set" id="your-group-id">
    <Parent guid="guidSHLMainMenu" id="..." />
</Group>

我希望能够找到一个 IDM_VS_CTXT _ 常数(或类似的东西)的 vsshlids.h 相匹配的命令ID ,但都能跟得上......相反,我发现 cmdidShellWindowNavigate7 cmdidShellWindowNavigate5 stdidcmd.h ;而只是试图出来......

I expected to find a IDM_VS_CTXT_ constant (or something similiar) in vsshlids.h that matches the command id, but nope... Instead I found cmdidShellWindowNavigate7 and cmdidShellWindowNavigate5 constants in stdidcmd.h; and just tried them out...

首先,我创建了新的ID,符号两个命令组...

First I created new id-symbols for two command groups...

<IDSymbol name="grpIdProjectContextAdd" value="0x1080" />
<IDSymbol name="grpIdSolutionContextAdd" value="0x1081" />

和命令......

<IDSymbol name="cmdIdAddItemHelloWorld" value="0x1082" />

比我定义了新的群体;并用所得到的命令标识符父...

Than I defined new groups; and used the obtained command identifiers as parent...

<Groups>
    <Group guid="your-command-set" id="grpIdProjectContextAdd">
        <Parent guid="guidSHLMainMenu" id="cmdidShellWindowNavigate7" />
    </Group>
    <Group guid="your-command-set" id="grpIdSolutionContextAdd">
        <Parent guid="guidSHLMainMenu" id="cmdidShellWindowNavigate5" />
    </Group>
</Groups>

当然,我需要一个按钮(这是摆在项目默认的添加菜单中)。

<Commands>
    <Button guid="your-command-set" 
            id="cmdIdAddItemHelloWorld" priority="0x1100" type="Button">
        <Parent guid="your-command-set" id="grpIdProjectContextAdd" />
        <Strings>
            <ButtonText>Hello World</ButtonText>
        </Strings>
    </Button>
</Commands>

为使按钮也出现在添加解决方案节点的菜单,我用命令的位置...

To make the button also appear in the Add menu of the solution node, I use a command placement...

<CommandPlacements>
    <CommandPlacement guid="your-command-set" 
                      id="cmdIdAddItemHelloWorld" priority="0x1100">
        <Parent guid="your-command-set" id="grpIdSolutionContextAdd" />
    </CommandPlacement>
 </CommandPlacements>

对于我来说,感觉有点哈克使用 cmdidShellWindowNavigate7 cmdidShellWindowNavigate5 常量,但结果我得到了这个...

For me, it feels a bit hacky to use the cmdidShellWindowNavigate7 and cmdidShellWindowNavigate5 constants, but in the result I got this...