Show a Visual Studio Extension Toolbar by default

2020-03-28 04:19发布

In a Visual Studio extension, I have defined a Toolbar in my .vsct file as:

      <Menu guid="guidVsCmdSet" id="MyToolbar" type="Toolbar" >
        <CommandFlag>TextChanges</CommandFlag>
        <CommandFlag>DefaultDocked</CommandFlag>      
        <Strings>
          <ButtonText>My Tools/ButtonText>
        </Strings>
      </Menu>

When I launch my extension in Visual Studio Experimental hive, I can open my Toolbar manually via right clicking in the CommandBar area.

Is there any way to have the toolbar show up by default when I first run the extension?

I have tried a couple other CommandFlags, but they did not seem to perform this behavior:

    <CommandFlag>AlwaysCreate</CommandFlag>
    <CommandFlag>DontCache</CommandFlag>   

2条回答
兄弟一词,经得起流年.
2楼-- · 2020-03-28 04:53

What you want to look at is Visibility Constraints. The below example uses GUID_TextEditorFactory which makes it visible when a text editor is active (and hide when, for example a designer is active).

I'm not 100% sure what the correct context is to make it always visible, but my guess is UICONTEXT_NoSolution (or maybe GUID_VSStandardCommandSet97).

<CommandTable>
    <Commands.../>
    <VisibilityConstraints>
        <VisibilityItem guid="guidVsCmdSet" id="MyToolbar" context="GUID_TextEditorFactory" />
    </VisibilityConstraints>
</CommandTable>
查看更多
够拽才男人
3楼-- · 2020-03-28 05:08

Read about how to do that in this workaround: LVN! Sidebar #7 - Showing a toolbar at Visual Studio startup

查看更多
登录 后发表回答