Search code examples
c#visual-studio-2017toolbarvisual-studio-extensionsvsix

How to activate by default the toolbar for a Visual Studio extension VSIX C# project


When I install for the first time the extension I want to see my toolbar without to activate it manually by right clicking on Visual Studio toolbar section and select my toolbar. I want to activate the toolbar just once, to inform the users about it's existence, but if it is manually disabled from VS then I want to keep it disable and use VS user settings.

My code from .vsct file is :

<Menu guid="guidPackageCmdSet" id="Toolbar" type="Toolbar">
  <CommandFlag>DefaultDocked</CommandFlag>
  <Strings>
    <ButtonText>My Toolbar</ButtonText>
    <CommandName>My Toolbar</CommandName>
  </Strings>
</Menu>

<Group guid="guidPackageCmdSet" id="ToolbarGroup" priority="0x0000">
  <Parent guid="guidPackageCmdSet" id="Toolbar" />
</Group>

<GuidSymbol name="guidPackageCmdSet" value="{498fdff5-5217-4da9-88d2-edad44ba3874}">
  <IDSymbol name="Toolbar" value="0x1000" />
  <IDSymbol name="ToolbarGroup" value="0x1050" />
</GuidSymbol>

Solution

  • What I did in the end was to store a hidden property using the attribute [Browsable(false)], with a default value set to true, in one of my Dialog Pages from extension and after the extension was installed for the first time I checked the property and I showed the toolbar as vorou's suggested in this link Showing a toolbar at Visual Studio startup and after that I changed the value for my property to false. Once the property was changed every time when a new instance of Visual Studio is started I checked the property but now nothing happens and Visual Studio will handle the toolbar just like the others. The bool property will be automatically preserved and it will never lose it's value. In this way the toolbar will appear after the installation but after that you can disable it and enable it again and the user setting will be preserved.