Search code examples
.netvisual-studio-2022vsixvsxvsixmanifest

Adding Visual Studio Commands (Buttons) to specific locations


I am creating own Microsoft Visual Studio 2022 Extension (Community VSIX Project), but currently I'm dyiing after couple of hours searching and testing different ways to do this very annoying stuff, which is putting my own menuitem exactly to the same group (line separated area under Tools menu) with Android, iOS and Archive Manager submenus.

I've brought it to appear under the Tools menu, but I want to put it here, above that Android submenuitem and this stackoverflow question didn't help me at all (https://stackoverflow.com/questions/6475068/placing-menu-options-in-visual-studio-extensions).

Also theoretical situation: What happens then when user haven't installed any Android or iOS developing workloads? Does my extension throw exception/do I have to then create my own group and put it there or does Visual Studio automaticly put it some rational location inside Tools section?

And here's current contents of my VSCommandTable.vsct:

<?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="MyIngeniousVSExt">
      
      <!--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="MyIngeniousVSExt" id="OpenDeviceManager" priority="0x0100" type="Button">
        <Parent guid="guidSHLMainMenu" id="IDG_VS_TOOLS_CMDLINE"/> <!-- I also tested eg. guid="VSMainMenu" id="Tools.ExtensibilityGroup" which also worked and when the item was in the highest section of Tools menu.-->
        <Icon guid="ImageCatalogGuid" id="ToolWindow" />
        <CommandFlag>IconIsMoniker</CommandFlag>
        <Strings>
          <ButtonText>MyIngeniousVSExt</ButtonText>
          <LocCanonicalName>.Tools.MyIngeniousVSExt</LocCanonicalName>
        </Strings>
      </Button>
    </Buttons>
  </Commands>

  <Symbols>
    <GuidSymbol name="MyIngeniousVSExt" value="{d98c1a7e-c9dc-4b3b-b1cd-cc54c3e5e4df}">
      <IDSymbol name="OpenDeviceManager" value="0x0100" />
    </GuidSymbol>
  </Symbols>
</CommandTable>

EnableVSIPLogging feature don't do anything!


Solution

  • I followed the instructions you mentioned above to use EnableVSIPLogging to identify menus and commands in my VS2022 community and it prints GUID and the CommandID in dialog.

    1.Enable VSIPLogging in the registry and the EnableVSIPLogging value would be located in a key that will look like this (17.0 will be something different, specific to your setup):

    Computer\HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\17.0_3d1fbd52\General
    

    enter image description here

    2.Once this is done you can CTRL+SHIFT click on "Android" and it will show you this: enter image description here

    The important values are the GUID and the CommandID.

    Here is a similar ticket you can refer to put your custom menu to specific locations.

    What happens then when user haven't installed any Android or iOS developing workloads?

    If you haven't installed any Android or IOS workloads, you maybe unable to get Android Menu's GUID and the CommandID. Therefore it seems impossible for you to add custom menu to the Android submenuitem.

    Hope it can help you.