1

The documentation of Visual Studio Extensions says that I can apply conditionals for the elements inside the vsct file.

https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/extensibility/vsct-xml-schema-conditional-attributes.md

I've been trying to build different menus for VS2019 and another one to the others. I've created a conditional compiltaion symbol which defines VS2019 for Visual Studio 2019+.

<Menu guid="GuidMenuSet" id="GroupIDMenuBaseGroup" priority="0x0100" type="Menu"
    Condition="Defined(VS2019)">
    <Parent guid="guidSHLMainMenu" id="IDG_VS_MM_TOOLSADDINS"/>    
    <Strings>
        <ButtonText>My Text</ButtonText>
        <CommandName>MyText</CommandName>
    </Strings>
</Menu>
<Menu guid="GuidMenuSet" id="GroupIDMenuBaseGroup"
    priority="0x0100" type="Menu"
    Condition="!Defined(VS2019)">
    <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>    
    <Strings>
        <ButtonText>My Text</ButtonText>
        <CommandName>MyText</CommandName>
    </Strings>
</Menu>

The menu does not appear on both VS2017 and VS2019.

gandarez
  • 2,609
  • 4
  • 34
  • 47

1 Answers1

2

The .VSCT file is compiled down to a binary command table output (.cto) resource, which is then embedded into your package assembly as a resource. This .cto resource is compiled at build time, with the conditionals being evaluated when the .cto resource is built.

Because your menu group is defined when you built the package, your menu group looks to be parented based upon which version of VS you built it with.

Sincerely,

Ed Dore
  • 2,013
  • 1
  • 10
  • 8
  • You're right. Do you know any alternative to put the menu under Tools for VS2017 and under Extensions for VS2019? @Ed-Dore – gandarez Jun 26 '19 at 12:51
  • 1
    I can't think of a good way to do this. Menu resources are not dynamically created/positioned at run time. The Extensions menu item was added in VS 2019 to try and address all the clutter from top level menus being added by different extensions. You might also reconsider keeping it under the Tools menu, so as to keep your user experience consistent. But to do this, you'll probably need two sets of dynamically visible commands, one under Tools, the other under Extensions. – Ed Dore Jun 26 '19 at 21:00
  • Starting with VS 2019, all top level menus are forced under the Extensions menu, is this correct? Specifying IDG_VS_MM_TOOLSADDINS or any other id makes no difference. Would appreciate it if you could comment on this. Regards. – Sabuncu Jul 05 '20 at 19:56