visual-studiovisual-studio-2017visual-studio-extensionsvisual-studio-2019vsct

Make extension to build different menus for two different versions of visual studio


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.


Solution

  • 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,