visual-studiossmsvisual-studio-extensionsvs-extensibilityvsct

Adding a Button/Command to Context Menu in SSMS SQL Query Editor Extension


I'm attempting to create a Visual Studio/SSMS extension that adds a command/button to the context menu in the SQL Query Editor window. Initially, I tried using IDM_VS_CTXT_CODEWIN. Although it works for new .txt files, it's not effective for .SQL files.

While researching this, I stumbled upon a suggestion to enable the 'EnableVSIPLogging' registry key to fetch more information about the context menu. Following that advice, Ctrl+Shift+RClick on the SQL Editor window gave me:

Guid = {33F13AC3-80B4ECE-85BC-225435603A5E}
GuidiD 240
CmdlD = 80
Type = 0x00000400
Flags = 0x00000000
NameLoc = (null)

However, I'm not sure how to use this information to find the correct parent ID.

Below is the snippet from my .vsct file:

<Group guid="guidColumnToCSVPackageCmdSet" id="MyEditorCtxGroup" priority="0x001">
    <Parent guid="guidSHLMainMenu" id=""/>
</Group>

I'm also uncertain if the Parent guid I've set is even the correct one for this purpose. Can someone guide me on how to use the provided GUID and other details to add the command to the context menu in the SQL Query Editor window? Any insights or pointers will be appreciated.


Solution

  • This one was a bear to find, and since Bing CoPilot wanted to only use your question as the answer, I had to do quite the bit of reverse engineering to find it.

    Firstly, the Guid in your example is missing a few characters.

    Guid =    {33F13AC3-80B4ECE-85BC-225435603A5E}
    Instead = {33F13AC3-80BB-4ECB-85BC-225435603A5E}
    

    Secondly, you have to convert the decimal 80 to a hexidecimal 0x0050.

    I have found it's more readable to add GuidSymbols then use text in your placements

    <Group guid="guidPasteCommandPackageCmdSet" id="PasteGroup" priority="0x0201">
        <Parent guid="queryWindowContextCommandSet" id="queryWindowContextMenu" />
    </Group>
    <GuidSymbol name="queryWindowContextCommandSet" value="{33F13AC3-80BB-4ECB-85BC-225435603A5E}">
        <IDSymbol name="queryWindowContextMenu" value="0x0050" />
    </GuidSymbol>
    

    I hope this helps!