visual-studio-2022vsix

Unable to add custom command to project's context menu in Visual Studio 2022 using VSIX Community toolkit


I am trying to a add a context menu to Project's context menu. One that is opened on right clicking the project file in Visual Studio

My VSCT file looks like this

<?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"/>
    <Include href="KnownImageIds.vsct"/>
    <Include href="VSGlobals.vsct"/>

    <Commands package="AnalyzerExtension">
        <Groups>
            <Group guid="AnalyzerExtension" id="MyMenuGroup" priority="0x0001">
                <Parent guid="VSMainMenu" id="ItemNode"/>
            </Group>
        </Groups>

        <!--This section defines the elements the user can interact with, like a menu command or a button
        or combo box in a toolbar. -->
        <Buttons>
            <Button guid="AnalyzerExtension" id="MyCommand" priority="0x0100" type="Button">
                <Parent guid="AnalyzerExtension" id="MyMenuGroup" />
                <Icon guid="ImageCatalogGuid" id="StatusInformation" />
                <CommandFlag>IconIsMoniker</CommandFlag>
                <Strings>
                    <ButtonText>My Command</ButtonText>
                    <LocCanonicalName>.AnalyzerExtension.MyCommand</LocCanonicalName>
                </Strings>
            </Button>
        </Buttons>
    </Commands>

    <CommandPlacements>
        <CommandPlacement guid="AnalyzerExtension" id="MyCommandPlacement" priority="0x0001" >
            <Parent guid="VSMainMenu" id="ItemNode"/>
        </CommandPlacement>
    </CommandPlacements>

    <Symbols>
        <GuidSymbol name="AnalyzerExtension" value="{5a8a77f2-be64-422c-9516-32e4cd00a008}">
            <IDSymbol name="MyMenuGroup" value="0x0001" />
            <IDSymbol name="MyCommand" value="0x0100" />
            <IDSymbol name="MyCommandPlacement" value="0x0200" />
        </GuidSymbol>
    </Symbols>
</CommandTable>

I wish to add code analysis code when command is clicked for a particular project


Solution

  • The Group should be placed under the ProjectNode menu not ItemNode menu.

       <Groups>
            <Group guid="AnalyzerExtension" id="MyMenuGroup" priority="0x0001">
                <Parent guid="VSMainMenu" id="ProjectNode"/>
            </Group>
        </Groups>