代码编辑器中没有出现.cs.html文件的上下文菜单项



我创建了一个Visual Studio扩展,它向右键单击两个位置时出现的上下文菜单添加了两个条目:解决方案资源管理器中的一个条目和打开的代码编辑器窗口中的任何位置。

我面临的问题是,如果正在编辑的文件是.cshtml文件,则在代码编辑器窗口中单击时不会出现菜单项(但在解决方案资源管理器中单击时会出现)。对于我测试过的任何其他文件类型,它都可以正常工作。

以下是我如何定义.vsct文件中的菜单项:

<Groups>
<Group guid="guidBrowseInRemoteGitRepoCommandPackageCmdSet" 
id="MyMenuGroup" priority="0x0600">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE"/>
</Group>
<Group guid="guidBrowseInRemoteGitRepoCommandPackageCmdSet" 
id="MyMenuGroup" priority="0x0600">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/>
</Group>
</Groups>
<Buttons>
<Button guid="guidBrowseInRemoteGitRepoCommandPackageCmdSet" 
id="BrowseInRemoteGitRepoCommandId" priority="0x0100" type="Button">
<Parent guid="guidBrowseInRemoteGitRepoCommandPackageCmdSet" id="MyMenuGroup" />
<Icon guid="guidImages" id="bmpPicGit" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Browse in remote repository</ButtonText>
</Strings>
</Button>
<Button guid="guidBrowseInRemoteGitRepoCommandPackageCmdSet"
id="CopyRemoteGitRepoUrlCommandId" priority="0x0100" type="Button">
<Parent guid="guidBrowseInRemoteGitRepoCommandPackageCmdSet" id="MyMenuGroup" />
<Icon guid="guidImages" id="bmpPicGit" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Copy URL of remote repository version</ButtonText>
</Strings>
</Button>
</Buttons>

菜单项被创建为命令构造函数中OleMenuCommand的实例:

var commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) 
as OleMenuCommandService;
if (commandService == null) return;
var browseMenuCommandID = new CommandID(CommandSet, BrowseCommandId);
var browseMenuItem = new OleMenuCommand(BrowseMenuItemCallback, browseMenuCommandID);
browseMenuItem.BeforeQueryStatus += MenuItemOnBeforeQueryStatus;
commandService.AddCommand(browseMenuItem);
//same for the other entry

MenuItemOnBeforeQueryStatus根据需要将senderVisibleEnabled设置为true或false。

那么,我在这里错过了什么?

编辑:

为了完整起见,以下是我需要在.vsct文件中进行的更改,以实现Carlos Quintero建议的更改:

1) 在<Symbols>中添加了以下内容:

<GuidSymbol name="guidCshtmlCodeEditor" value="{78F03954-2FB8-4087-8CE7-59D71710B3BB}" />

2) 在<Groups>中添加了以下内容:

<Group guid="guidBrowseInRemoteGitRepoCommandPackageCmdSet" id="MyMenuGroup" priority="0x0600">
<Parent guid="guidCshtmlCodeEditor" id="IDM_VS_TOOL_STANDARD"/>
</Group>
Ed.Dore的回答(https://social.msdn.microsoft.com/Forums/vstudio/en-US/7c5eb211-3985-426c-a3a2-9da4473dbaf4/my-context-menu-item-made-by-menu-command-in-visual-studio-package-is-not-shown-in-cshtml-files?forum=vsx):

cshtml文件显示了不同的上下文菜单。

如果使用EnableVSIPLogging注册表值(HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0\General),如本文所述:

http://blogs.msdn.com/b/dr._ex/archive/2007/04/17/using-enablevsiplogging-to-identify-menus-and-commands-with-vs-2005-sp1.aspx

您将看到有两个不同的上下文菜单在使用。

.CS文件使用:

Guid = {D309F791-903F-11D0-9EFC-00A0C911004F}
GuidID = 4
CmdID = 1037
Type = 0x00000400
Flags = 0x00000000
NameLoc = Code Window

和.CSHTML文件使用:

Guid = {78F03954-2FB8-4087-8CE7-59D71710B3BB}
GuidID = 395
CmdID = 1
Type = 0x00000400
Flags = 0x00000000
NameLoc = HTML Context

因此,您需要相应地修改.vsct文件。

最新更新