2012-01-03 2 views
1

Восстановление пакета NuGet не очень хорошо работает с пакетом PostSharp, это очень неприятно для меня и вручную редактирует файлы csproj быстро старение.Добавить кнопку в контекстное меню выгруженного проекта Visual Studio (не удается найти имя CommandBar)

Я хочу создать небольшую Visual Studio AddIn, которая исправляет проект для меня, добавив дополнительную кнопку в контекстное меню выгруженного проекта.

Проблема, с которой я сталкиваюсь, звучит просто, но преследует меня: я как-то не могу найти CommandBar для разгруженного контекстного меню проекта.

Таким образом, подведя итоги к вопросу: Каково имя CommandBar для контекстного меню без выгрузки проекта.

Большое спасибо!

+0

Поскольку порожний проект не так доступен через EnvDTE, кто-то написали хорошее решение для этого (открытия решения , и использовать это для использования MSBuild для открытия проекта): http://stackoverflow.com/questions/707107/library-for-parsing-visual-studio-solution-files –

ответ

1

Видимо: «Проект-заглушка». Найдено в списке по адресу: CommandBar names

Резюмируя метод OnConnection зарегистрировать это:

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 toolsMenuName = "Tools"; 

      //Place the command on the tools menu. 
      //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items: 
      Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"]; 

      //Find the Tools command bar on the MenuBar command bar: 
      CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName]; 
      CommandBars cmdBars = (CommandBars)(_applicationObject.CommandBars); 
      CommandBar vsBarProject = cmdBars["Stub Project"]; 
      CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl; 

      //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in, 
      // just make sure you also update the QueryStatus/Exec method to include the new command names. 
      try 
      { 
       //Add a command to the Commands collection: 
       Command command = commands.AddNamedCommand2(_addInInstance, "FixNuGetPostSharp", "Fix NuGet PostSharp", "Executes the command for VsextensionTest", true, 0, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); 

       //Add a control for the command to the tools menu: 
       if ((command != null) && (toolsPopup != null)) 
       { 
        command.AddControl(vsBarProject); 
       } 
      } 
      catch (System.ArgumentException) 
      { 
       //If we are here, then the exception is probably because a command with that name 
       // already exists. If so there is no need to recreate the command and we can 
       // safely ignore the exception. 
      } 
     } 
    }