简体   繁体   中英

How to add custom menu command to VSIX Error Context Menu

I looked at the MS docs on the VS menu list , and I can't find which menu ID to use. What I want to do is write a VSIX extension that gives me a menu pick when I right click on an Error message, and it will be able to obtain the contents of the selected error message.

Does anyone know if there is a way to customize that contextual menu?

在此处输入图像描述

Pick a menu command like "Previous Error" from the context menu, search the various .vsct files under "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VSSDK\VisualStudioIntegration\Common\Inc", and you should get a hit in the ShellCmdDef.vsct file.

  <Button Condition="!Defined(VSE)" guid="CLSID_VsTaskListPackage" id="cmdidErrorListPrevError" priority="0x0000" type="Button">
    <CommandFlag>AllowClientRole</CommandFlag>
    <CommandFlag>DefaultDisabled</CommandFlag>
    <CommandFlag>CommandWellOnly</CommandFlag>
    <Strings>
      <ButtonText>P&amp;revious Error</ButtonText>
      <CommandName>Previous Error</CommandName>
    </Strings>
  </Button>

Now you know the ID of the command (cmdidErrorListPrevError), so you can search for that, to find where/how it's placed.

You should get a hit in the ShellCmdPlace.vsct:

  <CommandPlacement guid="CLSID_VsTaskListPackage" id="cmdidErrorListPrevError" priority="0x0200">
    <Parent guid="guidSHLMainMenu" id="IDG_VS_ERRORLIST_NEXTPREV_ERR"/>
  </CommandPlacement>

Now search on that ID to find the menu that groupID is parented to, which will also take us to ShellCmdPlace.vsct and you can identify the actual context menu:

  <Group guid="guidSHLMainMenu" id="IDG_VS_ERRORLIST_NEXTPREV_ERR" priority="0x0400">
    <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ERRORLIST"/>
  </Group>

So now, you should define your own custom menu group parented off the same, with your commands parented to your custom menu group.

Caveat: This doesn't always work as there are a LOT of commands and menus that are not defined in the files included in the VSSDK. But for standard stuff like this, the technique "usually" works :-).

Sincerely,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM