Why does my extension's menu item not appear?

百般思念 提交于 2020-05-17 06:29:21

问题


I am building my first VS extension, to allow users to encrypt/decrypt the mailSettings/smtp section of web.config.

I wish to add a menu item that has 2 sub-items to the main VS Tools menu:

Config Encryptor
  Encrypt Mail Settings
  Decrypt Mail Settings

The relevant (I hope) parts of the .vsct file are as follows:

<Menus>
  <Menu guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenu" priority="0x0100" type="Menu">
    <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenuGroup" />
    <Strings>
      <MenuText>Config Encryptor</MenuText>
      <ButtonText>Config Encryptor</ButtonText>
      <CommandName>Config Encryptor</CommandName>
    </Strings>
  </Menu>
</Menus>

<Groups>      
  <Group guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenu" priority="0x0200">
    <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS" />
  </Group>
  <Group guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenuGroup" priority="0x0100">
    <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenu" />
  </Group>
</Groups>

<Buttons>
  <Button guid="guidEncryptConfigCommandPackageCmdSet" id="cmdidEncryptConfigCommand" priority="0x0100" type="Button">
    <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenuGroup" />
    <Strings>
      <ButtonText>Encrypt Mail Settings</ButtonText>
    </Strings>
  </Button>
  <Button guid="guidEncryptConfigCommandPackageCmdSet" id="cmdidDecryptConfigCommand" priority="0x0100" type="Button">
    <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenuGroup" />
    <Strings>
      <ButtonText>Decrypt Mail Settings</ButtonText>
    </Strings>
  </Button>
</Buttons>

<GuidSymbol name="guidEncryptConfigCommandPackageCmdSet" value="{2c763b06-e83f-4c03-8fc6-3a00416b361e}">
  <IDSymbol name="ConfigEncryptorMenu" value="0x1010" />
  <IDSymbol name="ConfigEncryptorMenuGroup" value="0x1020" />
  <IDSymbol name="cmdidEncryptConfigCommand" value="0x0100" />
  <IDSymbol name="cmdidDecryptConfigCommand" value="0x1021"  />
</GuidSymbol>

What am I doing wrong that the menu item doesn't appear when I debug the extension project in a new instance of VS?


回答1:


There's possibility it's because you've defined a menu whose ID is ConfigEncryptorMenuwhile you also defined a group whose ID is also ConfigEncryptorMenu, which messed up the structure.

Let's define a new IDSymbol called GroupForSubMenu:

<GuidSymbol name="guidEncryptConfigCommandPackageCmdSet" value="{2c763b06-e83f-4c03-8fc6-3a00416b361e}">
 ......
  <!-- New IDSymbol -->
  <IDSymbol name="GroupForSubMenu" value="0x1050"  />
</GuidSymbol>

Then change the content of first Group to:

  <Group guid="guidEncryptConfigCommandPackageCmdSet" id="GroupForSubMenu" priority="0x0200">
    <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS" />
  </Group>

And change the value of <Parent> in Menu section from:

<Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenuGroup" /> 

to <Parent guid="guidEncryptConfigCommandPackageCmdSet" id="GroupForSubMenu" />

The MenuText is not necessary and the original parent relationship seems to be something like ConfigEncryptorMenuGroup's parent is ConfigEncryptorMenu while ConfigEncryptorMenu's parent is ConfigEncryptorMenuGroup. Correct the relation ship between the groups and menus, the issue can be solved.



来源:https://stackoverflow.com/questions/57204804/why-does-my-extensions-menu-item-not-appear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!