title: VS2010 Add-In, adding a command to a context menu?
body: <p>I know there are already some threads about this, but I just won't work for me.</p>
  
  <p>What I want:
  I need a new entry in a context menu of the Visual Studio Source Control Explorer. For this I started a new Add-In Project.</p>
  
  <p>What I used:
  I used this article as a guide.
  <a href="http://blogs.msdn.com/b/team_foundation/archive/2010/06/24/extending-work-item-tracking-context-menus.aspx" rel="nofollow">http://blogs.msdn.com/b/team_foundation/archive/2010/06/24/extending-work-item-tracking-context-menus.aspx</a></p>
  
  <p>What is not working:
  I don't get any exceptions, the menu just won't show up, no matter where I add it.</p>
  
  <p>Some code snippets:</p>
  
  <pre><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
                  }
  }
  </code></pre>
  
  <p>I am using "Team Project" menu name for testing. VSIPLogging tells me, that this is the name of the menu if I make a right click on our TFS Team Project. I also tried other menus without success.</p>
  
  <p>Here are the AddCommandToContextMenu functions:</p>
  
  <pre><code>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);
      }
  </code></pre>
  
  <p>The commandbar "parent" gives me quite some exceptions, if I take a closer look at it:</p>
  
  <p>accChildCount = 'parent.accChildCount' threw an exception of type 'Microsoft.VisualStudio.PlatformUI.Automation.DeprecatedException'</p>
  
  <p>The same for every other "acc" value.</p>
  
  <p>Now I really don't know what I did wrong or what else I could try to make this work. All I want to do is to have a context menu entry in the source control explorer, which should call the power tools command line exe to call the "undo unchanged" function of it.</p>