问题描述
我正在构建我的第一个 VS 扩展,以允许用户加密/解密 web.config
的 mailSettings/smtp
部分.
I am building my first VS extension, to allow users to encrypt/decrypt the mailSettings/smtp
section of web.config
.
我想在主 VS 工具菜单中添加一个包含 2 个子项的菜单项:
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
.vsct
文件的相关(我希望)部分如下:
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>
在新的 VS 实例中调试扩展项目时菜单项没有出现是我做错了什么?
What am I doing wrong that the menu item doesn't appear when I debug the extension project in a new instance of VS?
推荐答案
有可能是因为你定义了一个 ID 为 ConfigEncryptorMenu
的 menu
而你还定义了一个group
的ID也是ConfigEncryptorMenu
,把结构搞乱了.
There's possibility it's because you've defined a menu
whose ID is ConfigEncryptorMenu
while you also defined a group
whose ID is also ConfigEncryptorMenu
, which messed up the structure.
让我们定义一个名为 GroupForSubMenu
的新 IDSymbol:
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>
然后将第一个Group的内容改为:
Then change the content of first Group to:
<Group guid="guidEncryptConfigCommandPackageCmdSet" id="GroupForSubMenu" priority="0x0200">
<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS" />
</Group>
并更改Menu
部分中的值:
<Parent guid="guidEncryptConfigCommandPackageCmdSet" id="ConfigEncryptorMenuGroup" />
到
MenuText 不是必需的,原始父级关系似乎类似于 ConfigEncryptorMenuGroup 的父级是 ConfigEncryptorMenu
而 ConfigEncryptorMenu 的父级是 ConfigEncryptorMenuGroup
.纠正组和菜单之间的关系,问题可以解决.
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.
这篇关于为什么我的扩展的菜单项没有出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!