Alex Rivera | Logout

Visual Studio 2010 Plug-in - Adding a context-menu to the Solution Explorer

Asked 2010-06-10T17:55:44.813
46

I want to add a new option in Visual Studio 2010's solution explorer's context menu for a specific file type. So for example, right clicking on a *.cs file will show the existing context menu plus "my new option".

I'm wondering what the code would look like; and would love a pointer to a good reference for developing visual studio plug-ins. The tutorials/references I'm seeing are conspicuously horrid.

Thanks!

Edit
Report

1 Answer

2

I found myself having to add an item to the code editor window context menu, which ended up being cmdBars["Script Context"] as I was wanting it specifically for JavaScript files.

As a technique for finding this which I felt useful sharing, I added the new menu item to all (456) menu controls in visual studio with the following loop:

foreach (CommandBar cc in cmdBars)
{
    if (cc.Index >= 1 && cc.Index <= 456)
    {
        command.AddControl(cmdBars[cc.NameLocal]);
    }
}

I then narrowed this using a divide and conquer technique by adjusting the bounds of the loop:

    if (cc.Index >= 1 && cc.Index <= 256)
    ...
    if (cc.Index >= 1 && cc.Index <= 128)
    ...
    if (cc.Index >= 64 && cc.Index <= 128)
    ...etc...

Until I eventually found what I was looking for.

(The related question for this is at Visual Studio 2010 Plug-in - Adding a context-menu to the Editor Window)

answered 2012-07-29T12:51:08.833

Your Answer