2013-09-30 81 views
0

我創建一個Visual Studio插件,但它增加了自己,當我一次又一次地打開Visual Studio。現在我有20個菜單在我的Visual Studio :)的Visual Studio插件始終將自身添加到菜單

如何檢查的,它已經加入或不?

我用Connect.cs下面的代碼[OnStartupComplete方法]

我看了有關添加分辯菜單此視頻http://msdn.microsoft.com/en-us/vstudio/bb614548.aspx

Command command = null; 
CommandBarControl commandBarControl; 
CommandBar commandBarASPX, commandBarCS; 
CommandBars commandBars; 

try 
{ 
    try 
    { 
     command = _applicationObject.Commands.Item(_addInInstance.ProgID + "." + AddInName); 
    } 
    catch 
    { 

    } 

    if (command == null) 
    { 
     command = _applicationObject.Commands.AddNamedCommand(_addInInstance, AddInName, AddInButtonName, AddInButtonTooltip, true, 528, null, (int)vsCommandStatus.vsCommandStatusEnabled | (int)vsCommandStatus.vsCommandStatusSupported); 
    } 
    else 
    { 
     commandBars = _applicationObject.CommandBars as CommandBars; 

     commandBarASPX = commandBars["ASPX Context"]; 
     commandBarControl = command.AddControl(commandBarASPX, commandBarASPX.Controls.Count + 1) as CommandBarControl; 

     commandBarCS = commandBars["Code Window"]; 
     commandBarControl = command.AddControl(commandBarCS, commandBarCS.Controls.Count + 1) as CommandBarControl; 
    } 
} 
catch (Exception exp) 
{ 
    MessageBox.Show(exp.Message.ToString()); 
} 

回答

0

看來你在的末尾添加命令每次啓動完成時,在「ASPX上下文」命令欄和「代碼窗口」命令欄中執行命令列表。

你還是在固定位置添加的命令,在命令欄說,在位置1,所以每次它可以添加的命令只有當它不存在。

所以,你可以嘗試以下方法:

commandBarControl = command.AddControl(commandBarASPX, 1) as CommandBarControl; 

// ... 

commandBarControl = command.AddControl(commandBarCS, 1) as CommandBarControl; 
相關問題