VS2010 Add-In by adding a command to the context menu?

I know that this already has some topics, but I just wonโ€™t work for me.

What I want: I need a new entry in the Visual Studio Source Control Explorer context menu. To do this, I started a new add-in project.

What I used: I used this article as a guide. http://blogs.msdn.com/b/team_foundation/archive/2010/06/24/extending-work-item-tracking-context-menus.aspx

What does not work: I have no exceptions, the menu simply will not appear, no matter where I add it.

Some snippets of code:

public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
if(connectMode == ext_ConnectMode.ext_cm_UISetup)
{
   AddCommandToContextMenu(
                         "Team Project", // context menu Name
                         "ClearQuery", // menu reference name
                         "Clear", // display name
                         47, // command icon
                         1);    // command placement, 1= first item on top
                }
}

I use the Team Project menu name for testing. VSIPLogging tells me that this is the name of the menu if I right-click on our Team TFS project. I also tried other menus without success.

AddCommandToContextMenu:

private void AddCommandToContextMenu(string menuName, string commandName, string commandText, int iconId, int position)
    {

                    CommandBar contextMenu = ((CommandBars)_applicationObject.CommandBars)[menuName];

                    AddCommand(contextMenu, commandName, commandText, iconId, position);
    }



private void AddCommand(CommandBar parent, string commandName, string commandText, int iconId, int position)

    {
                     Commands2 commands = (Commands2)_applicationObject.Commands;
                    //create the command
                    Command newCommand = commands.AddNamedCommand2(_addInInstance, commandName, commandText, commandText, true, iconId);
                    // add it to parent menu
                    newCommand.AddControl(parent, position);
    }

"parent" , :

accChildCount = 'parent.accChildCount' "Microsoft.VisualStudio.PlatformUI.Automation.DeprecatedException"

"acc".

, , . , , -, exe, " ".

+3
1

, Visual Studio CommnadBarPopup. , , / , , GC .

, AddCommand , Query/Exec, :

newCommand = commands.AddNamedCommand2(_addInInstance, commandName, commandText, commandText, true, iconId, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,(int)vsCommandStyle.vsCommandStylePictAndText,vsCommandControlType.vsCommandControlTypeButton);

, :

  • newCommand , , , ( , , , - , ).
  • , ref ContextGUIDS - [], , , , , , , : (int) vsCommandStatus.vsCommandStatusSupported + (int) vsCommandStatus.vsCommandStatusEnabled, , ( ).

, plaese : HOWTO: Visual Studio

!

+3

Source: https://habr.com/ru/post/1768023/


All Articles