'Visual Studio Extension Menu Group Visibility

Please go easy on me, I am new to Visual Studio Extension development, but inherited a sizable project. It targets VS2015-2019.

Within it, I have a menu group (not to be confused with menu item). When it is selected it will show the collection of menu items related to it as a sub menu.

Therefore, this thing groups menu items together and is not invoking a menu command itself, as would be the case for the menu items it contains.

I need to dynamically show/hide this group by setting the visibility on some sort of test. Despite reading a lot of the related topics here on SO and the MS docs, I cannot find this particular case being mentioned anywhere. Maybe I just didn't get a correct search hit from Google. Anyhow, anything I can find pertaining to visibility is always about a menu item (leaf node in the menu tree) and not actually a menu group.

As an aside, I had the same requirement for some menu items and I've sorted them out without any problem.

Here is the somewhat anonymized definition:

      <Menu guid="guidMyPackageCmdSet" id="SubMenu" priority="0x0007" type="Menu">
        <Parent guid="guidMyPackageCmdSet" id="MenuGroup" />
        <Strings>
          <ButtonText>Tool Name</ButtonText>
          <CommandName>ToolName</CommandName>
        </Strings>
      </Menu>

I tried adding the command flag for dynamic visibility to this and registering a command for SubMenu and placing my test in the BeforeQueryStatus. I also tried the same using MenuGroup.

Both didn't work.

How is one meant to control visibility of menu groups? Apologies if there is a really clear doc on this somewhere online - I just haven't located it yet and feel frustrated that such a fundamentally easy thing to conceive, should be any harder for menu groups than it is for menu items. I expected the menu system in a VS extension to be as straight forward as general .NET app development.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source