How can I add a cascading menu and group to the coding window context menu?

Ken Blaker 0 Reputation points
2025-04-16T17:21:28.4+00:00

A want to add a group of commands to the coding window context menu. My extension has a few commands. Rather than have them all show up in the context menu directly I'd like to have the context menu show a submenu - call it FooCommands, cascading to a list of my few commands.
I'm sure this is possible - I've seen other extensions do it - but I can't find any documentation for it.

I'm presuming this can all be done in the .vsct file. That's where i define my other references to the commands.

Visual Studio Extensions
Visual Studio Extensions
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Extensions: A program or program module that adds functionality to or extends the effectiveness of a program.
275 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. gekka 11,856 Reputation points MVP
    2025-04-17T03:34:31.9433333+00:00

    You can achieve having a submenu by using Menu instead of Button as the item.

    <?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"/>    
    
        <!--
            IDM_VS_CTXT_CODEWIN
             └ MyMenuGroup_1
                 ├ MyButton_1
                 └ MyMenu_1 👈
                     └ MyMenuGroup_2
                         ├ MyButton_2
                         └ MyButton_3
        -->
        
        <Commands package="guidVSIXTestProjectPackage">
    
            <Groups>
                <Group guid="guidVSIXTestProjectPackageCmdSet" id="MyMenuGroup_1" priority="0x0000">
                    <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/>
                </Group>
    
                <Group guid="guidVSIXTestProjectPackageCmdSet" id="MyMenuGroup_2" priority="0x0000">
                    <Parent guid="guidVSIXTestProjectPackageCmdSet" id="MyMenu_1"/>
                </Group>
            </Groups>
    
            <Menus>
                <Menu guid="guidVSIXTestProjectPackageCmdSet" id="MyMenu_1" type="Menu" priority="0x0101">
                    <Parent guid="guidVSIXTestProjectPackageCmdSet" id="MyMenuGroup_1"/>
                    <Strings>
                        <ButtonText>🆗 Sub Menu Parent</ButtonText>
                    </Strings>
                </Menu>
            </Menus>
    
            <Buttons>
                <Button guid="guidVSIXTestProjectPackageCmdSet" id="MyButton_1" priority="0x0100" type="Button">
                    <Parent guid="guidVSIXTestProjectPackageCmdSet" id="MyMenuGroup_1" />
                    <Strings>
                        <ButtonText>🆗 My Command 1</ButtonText>
                    </Strings>
                </Button>
    
                <Button guid="guidVSIXTestProjectPackageCmdSet" id="MyButton_2" priority="0x0100" type="Button">
                    <Parent guid="guidVSIXTestProjectPackageCmdSet" id="MyMenuGroup_2" />
                    <Strings>
                        <ButtonText>🆗 My Command 2</ButtonText>
                    </Strings>
                </Button>
    
                <Button guid="guidVSIXTestProjectPackageCmdSet" id="MyButton_3" priority="0x0101" type="Button">
                    <Parent guid="guidVSIXTestProjectPackageCmdSet" id="MyMenuGroup_2" />
                    <Strings>
                        <ButtonText>🆗 My Command 3</ButtonText>
                    </Strings>
                </Button>
            </Buttons>
    
        </Commands>
    
        <Symbols>
    
            <GuidSymbol name="guidVSIXTestProjectPackage" value="{634b60b0-ddf2-429d-a2e7-b5728d2b80e8}" />
    
            <GuidSymbol name="guidVSIXTestProjectPackageCmdSet" value="{9dafab8d-eddd-4d64-ac36-936ebf279b4d}">
                <IDSymbol name="MyMenuGroup_1" value="0x1020" />
                <IDSymbol name="MyMenuGroup_2" value="0x1021" />
    
                <IDSymbol name="MyMenu_1" value="0x1010" />
    
                <IDSymbol name="MyButton_1" value="0x0100" />
                <IDSymbol name="MyButton_2" value="0x0101" />
                <IDSymbol name="MyButton_3" value="0x0102" />
            </GuidSymbol>
        </Symbols>
    </CommandTable>
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.