I already have a package that I created, and I'd like to add a menu to the Code Window
context menu.
After a little search I found several articles explaining how to do it. The problem is, I can't get it work....
Here are my declarations in the vsct
file:
<Button guid="guidDALGeneratorPkgCmdSet" id="cmdidDataFlow" priority="0x0100" type="Button">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>cmdidDataFlow</CommandName>
<ButtonText>Show data flow</ButtonText>
</Strings>
</Button>
and the symbols:
<GuidSymbol name="guidDALGeneratorPkgCmdSet" value="{d3269a87-a721-49a5-800b-0464fbdfd313}">
<IDSymbol name="MyMenuGroup" value="0x1020" />
<IDSymbol name="cmdidDALGenerator" value="0x0101" />
<IDSymbol name="cmdidDataFlow" value="0x0102" />
</GuidSymbol>
and here is how I add my menu in my Package
class:
CommandID dataFlowCID = new CommandID(GuidList.guidDALGeneratorPkgCmdSet, (int)PkgCmdIDList.cmdidDataFlow);
OleMenuCommand dataFlowMenu = new OleMenuCommand(showDataFlow, dataFlowCID);
dataFlowMenu.BeforeQueryStatus += new EventHandler(dataFlowMenu_BeforeQueryStatus);
mcs.AddCommand(dataFlowMenu);
What am I doing wrong here? I must miss something because nearly every sample (and SO answer on the subject) suggests to add a menu that way in a package.....
What I have tried:
- make a group first then add my menu in that group: didn't work
- check if I use the right GUID (with this trick)
- use
IDG_VS_MENU_CONTEXTMENUS
instead ofIDM_VS_CTXT_CODEWIN
(after a look at this post: Using vsx how do you create a sub menu with commands?) - give the same parent as the menu that actually works to the second menu, still not showing....
- a lot of unsuccessful googling about my problem...
Also as you can see I use the BeforeQueryStatus
event, but it never gets fired...
For the ASPX/ASCX editor use this code:
Adding the Symbol for the context menu:
Adding the context menu:
More info at: https://stackoverflow.com/a/31769170/2235860
A context menu must be added to a group that is on the context menu for it to be displayed ... The syntax for this took me a couple days of trial and error to determine.
I created a new VSPackage extension project then updated my VSTS file as follows to create the context menu shown above:
For me, the mentioned constant worked. I started out with the standard template for a VSPackage in Visual Studio 2013, then changed the Parent id to IDM_VS_CTXT_CODEWIN.
Here's what I have now:
vsct:
the symbols:
Adding the menu item in the package class:
However, this only shows the menu in the "real" code window, not in the aspx/ascx editor for example.