I am using the following code to add a menu to visual studio here is the complete function (see below)
it works fine; the problem is when i take it to a test station (I mean when I move the dll), when I first open visual studio it shows the menu, then when I close visual studio and open it back, the menu does not show up
if I change the code when I put the menu under the tools menu, there is not problem
is there a way to fix that. I know by default visual studio add add in command to the tools menu, there must be a way to fix that
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)
{
object []contextGUIDS = new object[] { };
Commands2 commands = (Commands2)_applicationObject.Commands;
string testMenuName = "Test";
CommandBar menuBarCommandBar = ((CommandBars)_applicationObject.CommandBars)["MenuBar"];
CommandBarControl testControl = menuBarCommandBar.Controls[testMenuName];
try
{
CommandBarControl myControl = (CommandBarControl)menuBarCommandBar.FindControl(MsoControlType.msoControlPopup, System.Type.Missing, "MyAddin8", true, true);
if (myControl == null)
{
myControl = menuBarCommandBar.Controls.Add(Type: MsoControlType.msoControlPopup, Id: 1234567890, Before: testControl.Index);
myControl.Caption = "MyAddin8";
}
CommandBarPopup myControlPopup = (CommandBarPopup)myControl;
Command command = commands.AddNamedCommand2(_addInInstance, "MyCommand1", "MyCommand1", "Executes the command for MyCommand1", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
if((command != null) && (myControl != null))
{
command.AddControl(myControlPopup.CommandBar);
}
Command command2 = commands.AddNamedCommand2(_addInInstance, "MyCommand2", "MyCommand2", "Executes the command for MyCommand2", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
if ((command2 != null) && (myControl != null))
{
command2.AddControl(myControlPopup.CommandBar, 2);
}
}
catch(System.ArgumentException)
{
}
}
}