问题
Visual Studio 2019 16.5.0 preview 1.
I'm trying to get my menu items to show up either in a group or on a different menu.
Currently the menu items show up in the View/Other Windows menu on visual studio if I point them to IDG_VS_WNDO_OTRWNDWS1, but if I try to point them to MyMenuGroup, they just don't appear. The code will run but the menu items never show up on the menu. If I try to point the buttons to IDM_VS_MENU_EXTENSIONS, it won't even compile, giving the error below:
Undefined 'Parent/@id' attribute 'IDM_VS_MENU_EXTENSIONS' in a <Button> element
Below is my code:
<Groups>
<Group guid="MyGroupMenuSet" id="MyMenuGroup" priority="0x0100">
<Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1" />
</Group>
</Groups>
<Buttons>
<Button guid="My_ExtVS2019PackageCmdSet" id="cmdidMyWindowCommand" priority="0x0100" type="Button">
<!-- <Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1" /> -->
<Parent guid="MyGroupMenuSet" id="MyMenuGroup" />
<Strings>
<ButtonText>My Main Window</ButtonText>
</Strings>
</Button>
<Button guid="My_ExtVS2019PackageCmdSet" id="cmdidMyOtherControlCommand" priority="0x0100" type="Button">
<!--<Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1" />-->
<Parent guid="MyGroupMenuSet" id="MyMenuGroup" />
<Strings>
<ButtonText>My Other Window</ButtonText>
</Strings>
</Button>
</Buttons>
</Commands>
<Symbols>
<!-- This is the package guid. -->
<GuidSymbol name="My_ExtVS2019Package" value="{a28e16ed-f550-4cac-b087-f3728834a026}" />
<GuidSymbol value="{3d62bd83-4a3e-4e04-8ea8-800ea9316e90}" name="My_ExtVS2019PackageCmdSet">
<IDSymbol value="256" name="cmdidMyWindowCommand" />
<IDSymbol value="257" name="cmdidMyOtherControlCommand" />
</GuidSymbol>
<GuidSymbol value="{dd7dd38d-bf53-408e-baa4-c5c7c7774f19}" name="MyGroupMenuSet">
<IDSymbol value="4128" name="MyMenuGroup" />
<IDSymbol value="256" name="cmdidCommand1" />
</GuidSymbol>
</Symbols>
Any clue what's wrong with my code?
回答1:
Currently the menu items show up in the View/Other Windows menu on visual studio if I point them to IDG_VS_WNDO_OTRWNDWS1.
Button's parent should be a group
type. And IDG_VS_WNDO_OTRWNDWS1
is one child group of IDG_VS_VIEW_DEV_WINDOWS, so it works as we expected.
But if I try to point them to MyMenuGroup, they just don't appear.
MyMenuGroup
and IDG_VS_WNDO_OTRWNDWS1
also represent Group
type. One group's parent should be one menu instead of a group, or it won't work. See my another issue here.
So if you want to use your custom group, you should use this structure in xx.vsct
:Button => MyMenuGroup(group) => one menu(menu) => IDG_VS_WNDO_OTRWNDWS1(group)
instead of: Button => MyMenuGroup(group) => IDG_VS_WNDO_OTRWNDWS1(group)
Workaround:
Change this part:
<Groups>
<Group guid="MyGroupMenuSet" id="MyMenuGroup" priority="0x0100">
<Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1" />
</Group>
</Groups>
To:
<!--<Groups>
<Group guid="guidTestVSIXWindowPackageCmdSet" id="MyMenuGroup" priority="0x0600">
<Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1"/>
</Group>
</Groups>-->
<Menus>
<Menu guid="guidTestVSIXWindowPackageCmdSet" id="MyMenu" priority="0x0100" type="Menu">
<Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1"/>
<Strings>
<ButtonText>My Two Windows</ButtonText>
<CommandName>MyTwoWindows</CommandName>
</Strings>
</Menu>
</Menus>
<Groups>
<Group guid="guidTestVSIXWindowPackageCmdSet" id="MyMenuGroup" priority="0x0600">
<Parent guid="guidTestVSIXWindowPackageCmdSet" id="MyMenu"/>
</Group>
</Groups>
And don't forget to define the MyMenu
in GuidSymbol
:
<GuidSymbol value="{dd7dd38d-bf53-408e-baa4-c5c7c7774f19}" name="MyGroupMenuSet">
<IDSymbol value="4128" name="MyMenuGroup" />
<IDSymbol value="256" name="cmdidCommand1" />
<IDSymbol name="MyMenu" value="41" />
</GuidSymbol>
Then now VS can work to display your two windows in this way(View=>Other windows):
In addition: As for the Undefined IDM_VS_MENU_EXTENSIONS
, I've post the feedback here. In my opinion, this could be one issue about the document or the build tools package, anyone interested in it can track the issue and get the latest info there.
Hope it helps:)
来源:https://stackoverflow.com/questions/59202810/vsct-menu-items-not-showing