我在尝试将包从 Visual Studio 2008 移植到 2010 时遇到了一个问题,想知道是否有人有任何想法,请注意这在Visual Studio 2008 中有效,我不确定为什么它在 2010 年不起作用,
有问题的代码在这里:
IVsUIShell uiShell = (IVsUIShell)TestPackage.GetGlobalService(typeof (SVsUIShell));
Guid context = GuidList.GUIDTestMarkerCmdSet;
POINTS[] menuPos = new POINTS[1];
menuPos[0].x = (short)Cursor.Position.X;
menuPos[0].y = (short)Cursor.Position.Y;
var hr = uiShell.ShowContextMenu(0, ref context,(int)PkgCmdIDList.ContextMenu, menuPos, this); //access violation happens here.
if (hr != VSConstants.S_OK)
return VSConstants.S_FALSE;
break;
据我所知,uiShell 上下文是一个有效的 com 指针,我可以在它上面调用其他方法而不会爆炸。
我认为这与 xml vsct 文件中的上下文菜单设置有关。其中的相关部分可以在下面看到。
<Groups>
<Group guid="guidTestMarkerCmdSet" id="ContextGroup" priority="0x100" >
<Parent guid="guidTestMarkerCmdSet" id="ContextMenu"/>
</Group>
</Groups>
<Menus>
<Menu guid="guidTestMarkerCmdSet" id="ContextMenu" type="Context">
<Parent guid="guidTestMarkerCmdSet" id="0"/>
<Strings>
<ButtonText>Test Runner Context Menu</ButtonText>
<CommandName>TestRunnerContextMenu</CommandName>
</Strings>
</Menu>
</Menus>
<Buttons>
<Button guid="guidTestMarkerCmdSet" id="cmdRunTest" priority="0x1" type="Button">
<Parent guid="guidTestMarkerCmdSet" id="ContextGroup"/>
<Strings>
<ButtonText>Run Test</ButtonText>
<CommandName>cmdRunTest</CommandName>
</Strings>
</Button>
<Button guid="guidTestMarkerCmdSet" id="cmdDebugTest" priority="0x1" type="Button">
<Parent guid="guidTestMarkerCmdSet" id="ContextGroup"/>
<Strings>
<ButtonText>Debug Test</ButtonText>
<CommandName>cmdDebugTest</CommandName>
</Strings>
</Button>
任何帮助都会很受欢迎,我很迷惑
谢谢