简体   繁体   中英

how to create a solution right click top-level menu with sub-level button?(visual studio extension)

Visual Studio Version: 2019

I'm follow adding a menu to the visual studio menu bar to create menus, it works, the menus will be display ubder Extensions menu. Now, I want to move these menus to solution context menu, so I changed Menu > Parent > id to IDM_VS_CTXT_SOLNNODE . But it doesn't working.

Before:

<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <Extern href="stdidcmd.h"/>
  <Extern href="vsshlids.h"/>

  <Commands package="guidVSIXProject1Package">
    <Menus>
      <Menu guid="guidVSIXProject1PackageCmdSet" id="TopLevelMenu" priority="0x700" type="Menu">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_SOLNNODE" />
        <Strings>
          <ButtonText>TestMenu</ButtonText>
          <CommandName>TestMenu</CommandName>
        </Strings>
      </Menu>
    </Menus>

    <Groups>
      <Group guid="guidVSIXProject1PackageCmdSet" id="MyMenuGroup" priority="0x0600">
        <Parent guid="guidVSIXProject1PackageCmdSet" id="TopLevelMenu"/>
      </Group>
    </Groups>

    <Buttons>
      <Button guid="guidVSIXProject1PackageCmdSet" id="TestCommandId" priority="0x0100" type="Button">
        <Parent guid="guidVSIXProject1PackageCmdSet" id="MyMenuGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Invoke TestCommand</ButtonText>
        </Strings>
      </Button>
    </Buttons>

    <Bitmaps>
      <Bitmap guid="guidImages" href="Resources\TestCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
    </Bitmaps>
  </Commands>

  <Symbols>
    <GuidSymbol name="guidVSIXProject1Package" value="{fdde7b56-2c13-4a0b-bb96-d0b1c712c674}" />

    <GuidSymbol name="guidVSIXProject1PackageCmdSet" value="{23dc4a5e-5843-45cb-8b8b-c4a11184d73e}">
      <IDSymbol name="MyMenuGroup" value="0x1020" />
      <IDSymbol name="TestCommandId" value="0x0100" />
      <IDSymbol name="TopLevelMenu" value="0x1021"/>
    </GuidSymbol>

    <GuidSymbol name="guidImages" value="{f1008c6c-6b78-4876-93d1-b84e9a83c010}" >
      <IDSymbol name="bmpPic1" value="1" />
      <IDSymbol name="bmpPic2" value="2" />
      <IDSymbol name="bmpPicSearch" value="3" />
      <IDSymbol name="bmpPicX" value="4" />
      <IDSymbol name="bmpPicArrows" value="5" />
      <IDSymbol name="bmpPicStrikethrough" value="6" />
    </GuidSymbol>
  </Symbols>
</CommandTable>

After:

<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <Extern href="stdidcmd.h"/>
  <Extern href="vsshlids.h"/>

  <Commands package="guidVSIXProject1Package">
    <Menus>
      <Menu guid="guidVSIXProject1PackageCmdSet" id="TopLevelMenu" priority="0x700" type="Menu">
        <Parent guid="guidSHLMainMenu" id="IDG_VS_MM_TOOLSADDINS" /> <!--only change this id-->
        <Strings>
          <ButtonText>TestMenu</ButtonText>
          <CommandName>TestMenu</CommandName>
        </Strings>
      </Menu>
    </Menus>
    <!--same with before-->
</CommandTable>

You should sets <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_SOLNNODE" /> in one group instead of one menu.

Change it from:

<Groups>
  <Group guid="guidVSIXProject1PackageCmdSet" id="MyMenuGroup" priority="0x0600">
    <Parent guid="guidVSIXProject1PackageCmdSet" id="TopLevelMenu"/>
  </Group>
</Groups>

To:

<Groups>
  <Group guid="guidVSIXProject2PackageCmdSet" id="MyMenuGroup" priority="0x0600">
    <!--<Parent guid="guidVSIXProject2PackageCmdSet" id="TopLevelMenu"/>-->
    <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_SOLNNODE"/>
  </Group>
</Groups>

This will move your menu from Extensions top menu to Solution context(right-click solution).

But this also means you can't find the command from top-menu any more, if you want to make the command available both in Top-menu and Solution context, please consider using CommandPlacements .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM