Visual studio 如何为VS扩展嵌套工具菜单按钮?

Visual studio 如何为VS扩展嵌套工具菜单按钮?,visual-studio,menu,menuitem,visual-studio-extensions,Visual Studio,Menu,Menuitem,Visual Studio Extensions,我正在构建我的第一个VS扩展,因此我目前在这方面的技能相当于以下教程和提问。扩展名用于加密/解密web应用程序项目的web.config文件的一部分。我有两个命令,目前按钮在.vsct文件中设置如下: <Buttons> <Button guid="guidEncryptConfigCommandPackageCmdSet" id="EncryptConfigCommandId" priority="0x0100" type="Button"> <Par

我正在构建我的第一个VS扩展,因此我目前在这方面的技能相当于以下教程和提问。扩展名用于加密/解密web应用程序项目的
web.config
文件的一部分。我有两个命令,目前按钮在
.vsct
文件中设置如下:

<Buttons>
  <Button guid="guidEncryptConfigCommandPackageCmdSet" id="EncryptConfigCommandId" priority="0x0100" type="Button">
    <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="MyMenuGroup" />
    <Strings>
      <ButtonText>Encrypt Mail Settings</ButtonText>
    </Strings>
  </Button>
  <Button guid="guidEncryptConfigCommandPackageCmdSet" id="cmdidDecryptConfigCommand" priority="0x0100" type="Button">
    <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="MyMenuGroup" />
    <Strings>
      <ButtonText>Decrypt Mail Settings</ButtonText>
    </Strings>
  </Button>
</Buttons>
Encrypt Mail Settings
Decrypt Mail Settings
我希望在
工具
菜单中只有一个顶级按钮,带有两个嵌套按钮,每个操作一个,例如:

Config Encryptor
...Encrypt Mail Settings
...Decrypt Mail Settings

如何实现我想要的结果?

您需要为按钮创建
菜单

    <Menus>
      <Menu guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenu" priority="0x0100" type="Menu">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenuGroup"/>
        <Strings>
          <MenuText>Config Encryptor</MenuText>
          <ButtonText>Config Encryptor</ButtonText>
          <CommandName>Config Encryptor</CommandName>
        </Strings>
      </Menu>
   </Menus>
另外,不要忘记为
组和
组菜单添加
IDSymbol

并为有关此问题的相关文档设置正确的工具名称:
id=“ToolsMenu”

Tools menu in IDE
  --SubMenuGroup
     --SubMenu1
        --ButtonsGroup
           --EncryptConfigCommandId(Encrypt Mail Settings)
           --DecryptConfigCommandId(Decrypt Mail Settings)
<Commands package="guidEncryptConfigCommandPackage">
    <Menus>
      <Menu guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1" priority="0x0100" type="Menu">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup"/>
        <Strings>
          <ButtonText>Config Encryptor</ButtonText>
          <CommandName>Config Encryptor</CommandName>
        </Strings>
      </Menu>
    </Menus>

    <Groups>
      <Group guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" priority="0x0600">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1"/>
      </Group>
      <Group guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup" priority="0x0600">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
      </Group>
    </Groups>

    <Buttons>
      <Button guid="guidEncryptConfigCommandPackageCmdSet" id="EncryptConfigCommandId" priority="0x0100" type="Button">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Encrypt Mail Settings</ButtonText>
        </Strings>
      </Button>

      <Button guid="guidEncryptConfigCommandPackageCmdSet" id="DecryptConfigCommandId" priority="0x0110" type="Button">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Decrypt Mail Settings</ButtonText>
        </Strings>
      </Button>
    </Buttons>

    <!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
    <Bitmaps>
      <Bitmap guid="guidImages" href="Resources\EncryptConfigCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
    </Bitmaps>
  </Commands>
<!-- This is the guid used to group the menu commands together -->
    <GuidSymbol name="guidEncryptConfigCommandPackageCmdSet" value="{70c1a496-88b4-4c83-8539-39decdbdb8fb}">
      <IDSymbol name="ButtonsGroup" value="0x1020" />
      <IDSymbol name="EncryptConfigCommandId" value="0x0100" />
      <IDSymbol name="DecryptConfigCommandId" value="0x0110" />
      <IDSymbol name="SubMenu1" value="0x1100"/>
      <IDSymbol name="SubMenuGroup" value="0x1150"/>
    </GuidSymbol>

我们想要什么:

Tools menu in IDE
  --SubMenuGroup
     --SubMenu1
        --ButtonsGroup
           --EncryptConfigCommandId(Encrypt Mail Settings)
           --DecryptConfigCommandId(Decrypt Mail Settings)
<Commands package="guidEncryptConfigCommandPackage">
    <Menus>
      <Menu guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1" priority="0x0100" type="Menu">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup"/>
        <Strings>
          <ButtonText>Config Encryptor</ButtonText>
          <CommandName>Config Encryptor</CommandName>
        </Strings>
      </Menu>
    </Menus>

    <Groups>
      <Group guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" priority="0x0600">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1"/>
      </Group>
      <Group guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup" priority="0x0600">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
      </Group>
    </Groups>

    <Buttons>
      <Button guid="guidEncryptConfigCommandPackageCmdSet" id="EncryptConfigCommandId" priority="0x0100" type="Button">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Encrypt Mail Settings</ButtonText>
        </Strings>
      </Button>

      <Button guid="guidEncryptConfigCommandPackageCmdSet" id="DecryptConfigCommandId" priority="0x0110" type="Button">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Decrypt Mail Settings</ButtonText>
        </Strings>
      </Button>
    </Buttons>

    <!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
    <Bitmaps>
      <Bitmap guid="guidImages" href="Resources\EncryptConfigCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
    </Bitmaps>
  </Commands>
<!-- This is the guid used to group the menu commands together -->
    <GuidSymbol name="guidEncryptConfigCommandPackageCmdSet" value="{70c1a496-88b4-4c83-8539-39decdbdb8fb}">
      <IDSymbol name="ButtonsGroup" value="0x1020" />
      <IDSymbol name="EncryptConfigCommandId" value="0x0100" />
      <IDSymbol name="DecryptConfigCommandId" value="0x0110" />
      <IDSymbol name="SubMenu1" value="0x1100"/>
      <IDSymbol name="SubMenuGroup" value="0x1150"/>
    </GuidSymbol>
单击VS=>显示
配置加密机
子菜单中的
工具
菜单,单击
配置加密机
菜单将显示
加密邮件设置
解密邮件设置
命令

我的xx.vsct中的结构:

Tools menu in IDE
  --SubMenuGroup
     --SubMenu1
        --ButtonsGroup
           --EncryptConfigCommandId(Encrypt Mail Settings)
           --DecryptConfigCommandId(Decrypt Mail Settings)
<Commands package="guidEncryptConfigCommandPackage">
    <Menus>
      <Menu guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1" priority="0x0100" type="Menu">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup"/>
        <Strings>
          <ButtonText>Config Encryptor</ButtonText>
          <CommandName>Config Encryptor</CommandName>
        </Strings>
      </Menu>
    </Menus>

    <Groups>
      <Group guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" priority="0x0600">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1"/>
      </Group>
      <Group guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup" priority="0x0600">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
      </Group>
    </Groups>

    <Buttons>
      <Button guid="guidEncryptConfigCommandPackageCmdSet" id="EncryptConfigCommandId" priority="0x0100" type="Button">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Encrypt Mail Settings</ButtonText>
        </Strings>
      </Button>

      <Button guid="guidEncryptConfigCommandPackageCmdSet" id="DecryptConfigCommandId" priority="0x0110" type="Button">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Decrypt Mail Settings</ButtonText>
        </Strings>
      </Button>
    </Buttons>

    <!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
    <Bitmaps>
      <Bitmap guid="guidImages" href="Resources\EncryptConfigCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
    </Bitmaps>
  </Commands>
<!-- This is the guid used to group the menu commands together -->
    <GuidSymbol name="guidEncryptConfigCommandPackageCmdSet" value="{70c1a496-88b4-4c83-8539-39decdbdb8fb}">
      <IDSymbol name="ButtonsGroup" value="0x1020" />
      <IDSymbol name="EncryptConfigCommandId" value="0x0100" />
      <IDSymbol name="DecryptConfigCommandId" value="0x0110" />
      <IDSymbol name="SubMenu1" value="0x1100"/>
      <IDSymbol name="SubMenuGroup" value="0x1150"/>
    </GuidSymbol>
命令
部分的真实内容:

Tools menu in IDE
  --SubMenuGroup
     --SubMenu1
        --ButtonsGroup
           --EncryptConfigCommandId(Encrypt Mail Settings)
           --DecryptConfigCommandId(Decrypt Mail Settings)
<Commands package="guidEncryptConfigCommandPackage">
    <Menus>
      <Menu guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1" priority="0x0100" type="Menu">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup"/>
        <Strings>
          <ButtonText>Config Encryptor</ButtonText>
          <CommandName>Config Encryptor</CommandName>
        </Strings>
      </Menu>
    </Menus>

    <Groups>
      <Group guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" priority="0x0600">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1"/>
      </Group>
      <Group guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup" priority="0x0600">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
      </Group>
    </Groups>

    <Buttons>
      <Button guid="guidEncryptConfigCommandPackageCmdSet" id="EncryptConfigCommandId" priority="0x0100" type="Button">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Encrypt Mail Settings</ButtonText>
        </Strings>
      </Button>

      <Button guid="guidEncryptConfigCommandPackageCmdSet" id="DecryptConfigCommandId" priority="0x0110" type="Button">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Decrypt Mail Settings</ButtonText>
        </Strings>
      </Button>
    </Buttons>

    <!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
    <Bitmaps>
      <Bitmap guid="guidImages" href="Resources\EncryptConfigCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
    </Bitmaps>
  </Commands>
<!-- This is the guid used to group the menu commands together -->
    <GuidSymbol name="guidEncryptConfigCommandPackageCmdSet" value="{70c1a496-88b4-4c83-8539-39decdbdb8fb}">
      <IDSymbol name="ButtonsGroup" value="0x1020" />
      <IDSymbol name="EncryptConfigCommandId" value="0x0100" />
      <IDSymbol name="DecryptConfigCommandId" value="0x0110" />
      <IDSymbol name="SubMenu1" value="0x1100"/>
      <IDSymbol name="SubMenuGroup" value="0x1150"/>
    </GuidSymbol>
根据上述三个文件:

Tools menu in IDE
  --SubMenuGroup
     --SubMenu1
        --ButtonsGroup
           --EncryptConfigCommandId(Encrypt Mail Settings)
           --DecryptConfigCommandId(Decrypt Mail Settings)
<Commands package="guidEncryptConfigCommandPackage">
    <Menus>
      <Menu guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1" priority="0x0100" type="Menu">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup"/>
        <Strings>
          <ButtonText>Config Encryptor</ButtonText>
          <CommandName>Config Encryptor</CommandName>
        </Strings>
      </Menu>
    </Menus>

    <Groups>
      <Group guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" priority="0x0600">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1"/>
      </Group>
      <Group guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup" priority="0x0600">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
      </Group>
    </Groups>

    <Buttons>
      <Button guid="guidEncryptConfigCommandPackageCmdSet" id="EncryptConfigCommandId" priority="0x0100" type="Button">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Encrypt Mail Settings</ButtonText>
        </Strings>
      </Button>

      <Button guid="guidEncryptConfigCommandPackageCmdSet" id="DecryptConfigCommandId" priority="0x0110" type="Button">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Decrypt Mail Settings</ButtonText>
        </Strings>
      </Button>
    </Buttons>

    <!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
    <Bitmaps>
      <Bitmap guid="guidImages" href="Resources\EncryptConfigCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
    </Bitmaps>
  </Commands>
<!-- This is the guid used to group the menu commands together -->
    <GuidSymbol name="guidEncryptConfigCommandPackageCmdSet" value="{70c1a496-88b4-4c83-8539-39decdbdb8fb}">
      <IDSymbol name="ButtonsGroup" value="0x1020" />
      <IDSymbol name="EncryptConfigCommandId" value="0x0100" />
      <IDSymbol name="DecryptConfigCommandId" value="0x0110" />
      <IDSymbol name="SubMenu1" value="0x1100"/>
      <IDSymbol name="SubMenuGroup" value="0x1150"/>
    </GuidSymbol>
1.我们可以根据第一个文档向现有菜单或自定义菜单添加子菜单。文档中没有明确描述如何构造
按钮、菜单、组以及它们之间的关系,但检查其代码中的内容我们可以找到1。要将
子菜单
添加到
工具菜单
,我们需要将组设置为其父菜单,然后将
工具菜单
设置为其父菜单

2.要将两个按钮组合成一个子菜单,我们需要将两个按钮的父项设置为GroupB,然后将子菜单设置为GroupB的父项

3.根据第三个文档,Visual Studio菜单栏上的菜单和组使用GUID guidshlmain菜单。
Tools menu
的ID是
IDM\u VS\u menu\u Tools

这就是为什么我在这个结构中编辑内容,幸运的是它可以工作。由于我可能会误解文件中的某些内容,如果有什么错误或更好的地方,请随时纠正我:)

调试时的外观:

Tools menu in IDE
  --SubMenuGroup
     --SubMenu1
        --ButtonsGroup
           --EncryptConfigCommandId(Encrypt Mail Settings)
           --DecryptConfigCommandId(Decrypt Mail Settings)
<Commands package="guidEncryptConfigCommandPackage">
    <Menus>
      <Menu guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1" priority="0x0100" type="Menu">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup"/>
        <Strings>
          <ButtonText>Config Encryptor</ButtonText>
          <CommandName>Config Encryptor</CommandName>
        </Strings>
      </Menu>
    </Menus>

    <Groups>
      <Group guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" priority="0x0600">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenu1"/>
      </Group>
      <Group guid="guidEncryptConfigCommandPackageCmdSet" id="SubMenuGroup" priority="0x0600">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
      </Group>
    </Groups>

    <Buttons>
      <Button guid="guidEncryptConfigCommandPackageCmdSet" id="EncryptConfigCommandId" priority="0x0100" type="Button">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Encrypt Mail Settings</ButtonText>
        </Strings>
      </Button>

      <Button guid="guidEncryptConfigCommandPackageCmdSet" id="DecryptConfigCommandId" priority="0x0110" type="Button">
        <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ButtonsGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Decrypt Mail Settings</ButtonText>
        </Strings>
      </Button>
    </Buttons>

    <!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
    <Bitmaps>
      <Bitmap guid="guidImages" href="Resources\EncryptConfigCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
    </Bitmaps>
  </Commands>
<!-- This is the guid used to group the menu commands together -->
    <GuidSymbol name="guidEncryptConfigCommandPackageCmdSet" value="{70c1a496-88b4-4c83-8539-39decdbdb8fb}">
      <IDSymbol name="ButtonsGroup" value="0x1020" />
      <IDSymbol name="EncryptConfigCommandId" value="0x0100" />
      <IDSymbol name="DecryptConfigCommandId" value="0x0110" />
      <IDSymbol name="SubMenu1" value="0x1100"/>
      <IDSymbol name="SubMenuGroup" value="0x1150"/>
    </GuidSymbol>

此外:

1.关于管理命令的处理程序,请参阅

2.查看哪个指示将子菜单添加到另一个VS菜单,在此过程中我们需要一个组。
若要将组添加到现有Visual Studio菜单,请将以下菜单之一设置为其父菜单。

您好,朋友,是否有此问题的更新?请检查vik_78的回答是否有助于解决此问题。此外,您可能会从中得到一个提示,希望它能有所帮助:)。这三个文件正是您需要的,我只是按照它们来做,而且它是有效的,如果可能的话,我会在稍后的回答中尝试详细描述它。谢谢,但我不太明白这一点。您的菜单只有一个项目,或者我需要为每个命令创建一个单独的
菜单
项目吗?@ProfK您应该将菜单设置为组的父项。并将此组设置为按钮的父级