Adding a new command to the Output Window's context menu

Maciek 20 Reputation points
2025-04-14T09:56:34.5733333+00:00

I've been trying for several hours to extend the context menu of the Output window in Visual Studio 2022, so that clicking on it with the left mouse button would display an item linked to my custom command.

I want to

  • select text in the Output window while debugging,
  • right-click on it,
  • and choose a command that will be executed for the selected text.

How can I extend the context menu of the Output window?

To help with this, I installed Command Explorer by Mads Kristensen, which allowed me to find the proper (I hope) GUID and ID for the context menu. For the Output window context menu, I’m using the following:

<GuidSymbol name="DocumentWindowCommandSet" value="{C9DD4A59-47FB-11D2-83E7-00C04F9902C1}">
  <IDSymbol name="DocumentContextMenu" value="0x155"/>
</GuidSymbol>

Guid and ID I take from: CommandExplorer

commandExp

I also found and reviewed these related questions on stackoverflow:

or

However, none of them helped resolve my issue.

ChatGPT suggests using IDM_VS_CTXT_OUTPUTWINDOW, but such an identifier does not exist in vsshlids.h

Here is the current version of my .vsct file:


<?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="guidOutputMenuExtensionPackage">

    <Groups>
      <Group guid="guidOutputMenuExtensionPackageCmdSet" id="MyMenuGroup" priority="0x0600">
        <Parent guid="DocumentWindowCommandSet" id="DocumentContextMenu"/>
      </Group>
    </Groups>

    <Buttons>
      <Button guid="guidOutputMenuExtensionPackageCmdSet" id="Command1Id" priority="0x0100" type="Button">
        <Parent guid="guidOutputMenuExtensionPackageCmdSet" id="MyMenuGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>EXECUTE Command1</ButtonText>
        </Strings>
      </Button>
    </Buttons>

    <Bitmaps>
      <Bitmap guid="guidImages" href="Resources\Command1.png" usedList="bmpPic1"/>
    </Bitmaps>

  </Commands>

  <Symbols>
    <GuidSymbol name="guidOutputMenuExtensionPackage" value="{9b255e13-1ab1-4a41-9bf8-194e2af5e5cb}" />

    <GuidSymbol name="DocumentWindowCommandSet" value="{C9DD4A59-47FB-11D2-83E7-00C04F9902C1}">
      <IDSymbol name="DocumentContextMenu" value="0x155"/>
    </GuidSymbol>

    <GuidSymbol name="guidOutputMenuExtensionPackageCmdSet" value="{30af3ca6-21df-4c44-adc4-fbe04533b289}">
      <IDSymbol name="MyMenuGroup" value="0x1020" />
      <IDSymbol name="Command1Id" value="0x0100" />
    </GuidSymbol>

    <GuidSymbol name="guidImages" value="{a132bff6-58d4-4a7f-835f-b910a930003f}" >
      <IDSymbol name="bmpPic1" value="1" />
    </GuidSymbol>
  </Symbols>
</CommandTable>
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.
274 questions
0 comments No comments
{count} votes

Accepted answer
  1. gekka 11,776 Reputation points MVP
    2025-04-15T23:34:50.4+00:00

    The context menu id written in vsshlids.h begins with IDM_VS_CTXT_*.

    <?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="guidVSIXTestProjectPackage">
    
        <Groups>
          <Group guid="guidVSIXTestProjectPackageCmdSet" id="MyMenuGroup" priority="0x0600">
            <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_RESULTSLIST"/> <!--  use IDM_VS_CTXT_RESULTSLIST    -->
          </Group>
        </Groups>
    
        <Buttons>
          <Button guid="guidVSIXTestProjectPackageCmdSet" id="Command1Id" priority="0x0100" type="Button">
    
            <Parent guid="guidVSIXTestProjectPackageCmdSet" id="MyMenuGroup" />
    
            <Strings>
              <ButtonText>🆗 This is My Command</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" value="0x1020" />
          <IDSymbol name="Command1Id" value="0x0100" />
        </GuidSymbol>
    
      </Symbols>
    </CommandTable>
    

0 additional answers

Sort by: Most helpful

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.