Oct 082008

Here’s a quick note for a solution I discovered the hard way that isn’t covered well in the MSDN documentation:  If you are writing a Visual Studio extension and adding a menu item to an existing menu (such as the project context menu) using a .vsct (Visual Studio XML Command Table) file, the priority field of the menu item has no effect on the placement of the item within the context menu.  If you want to position your new menu item above or below another item, you need to fiddle with the priority field of your menu item’s group.

The menu item’s priority affects the positioning of the item relative to other items within the same menu group.  The menu item’s group affects the positioning of its menu item(s) relative to other groups.  Since you can’t define a menu item without a group, macro level placement is controlled by the group priority, not the menu item priority.

The other challenge to positioning a new menu item where you want it within an existing VS menu is figuring out what the priorities are of the existing menu items/groups.  I found the VSCT PowerToy to be somewhat useful for this.  It’s difficult to use, but after fiddling with it for awhile and trying different search queries you’ll eventually figure out how to get what you’re looking for.

In my case, I was trying to add a new menu item to my project node’s context menu, and have the new menu item appear near the bottom of the context menu, but above the Properties menu which is traditionally always at the very bottom.  I needed to know what priority value the existing Properties group was using and the priority of the menus just before it so that I could set my menu’s group priority to something in between. 

Searching for IDM_VS_CTXT_PROJNODE in VSCT PowerToy returns the project node’s context menu and all of the items within it.  From there you can browse through the menu items noting their priority values and pick the right value to position your menu where you want it.