【问题标题】:Visual Studio Add-In always adds itself to menuVisual Studio 加载项始终将自身添加到菜单中
【发布时间】:2013-10-06 03:39:12
【问题描述】:

我创建了一个 Visual Studio 插件,但是当我一次又一次地打开 Visual Studio 时它会自行添加。现在我的视觉工作室中有 20 个菜单 :)

如何查看是否已添加?

我在 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());
}

【问题讨论】:

    标签: c# visual-studio-2010 visual-studio


    【解决方案1】:

    每次启动完成时,您似乎都在“ASPX 上下文”命令栏和“代码窗口”命令栏中的命令列表末尾添加命令。

    您应该将命令添加到命令栏中的固定位置,例如位置 1,这样每次只有在命令不存在时才能添加命令。

    所以你可以尝试以下方法:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多