首页 > 解决方案 > 创建 Visual Studio 扩展添加菜单和表单

问题描述

我正在尝试将一个菜单项添加到我的 Visual Studio 自定义扩展中,但是当我尝试编译它时说 guidTopLevelMenuPackageCmdSet 不存在,即使我已经创建了一个命令对象。

<Menus>
  <Menu guid="CommandSet" id="TopLevelMenu" priority="0x700" type="Menu">
  <Parent guid="guidSHLMainMenu"
          id="IDG_VS_MM_TOOLSADDINS" />
      <Strings>
          <ButtonText>TestMenu</ButtonText>
          <CommandName>TestMenu</CommandName>
      </Strings>
  </Menu>
</Menus>
 
  <!-- In this section you can define new menu groups. A menu group is a container for
     other menus or buttons (commands); from a visual point of view you can see the
     group as the part of a menu contained between two lines. The parent of a group
     must be a menu. -->
  <Groups>
      <Group guid="CommandSet" id="MyMenuGroup" priority="0x0600">
          <Parent guid="CommandSet" id="TopLevelMenu"/>
      </Group>
  </Groups>

现在我希望我的扩展程序能够启动一个表单我如何正确地实现这一点我在这里尝试了教程,但不清楚你从哪里获得指南。https://www.c-sharpcorner.com/article/creating-visual-studio-2019-extension/

我从基本模板开始,但是当我调试时它没有正确添加菜单是他们缺少的东西。

<!-- In this section you can define new menu groups. A menu group is a container for
         other menus or buttons (commands); from a visual point of view you can see the
         group as the part of a menu contained between two lines. The parent of a group
         must be a menu. -->
      <Menus>
          <Menu guid="CommandSet" id="TopLevelMenu" priority="0x700" type="Menu">
              <Parent guid="guidSHLMainMenu"
                      id="IDG_VS_MM_TOOLSADDINS" />
              <Strings>
                  <ButtonText>TestMenu</ButtonText>
                  <CommandName>TestMenu</CommandName>
              </Strings>
          </Menu>
      </Menus>
     
      <!-- In this section you can define new menu groups. A menu group is a container for
         other menus or buttons (commands); from a visual point of view you can see the
         group as the part of a menu contained between two lines. The parent of a group
         must be a menu. -->
      <Groups>
          <Group guid="CommandSet" id="MyMenuGroup" priority="0x0600">
              <Parent guid="CommandSet" id="TopLevelMenu"/>
          </Group>
      </Groups>

标签: c#vsix

解决方案


对于其他任何人,如果您查看 vscx 文件,您将在底部看到以下内容。在这里,您将看到 guidEfCoreCrudBootStrapPackageCmdSet 与您在教程中创建的 ICommand 界面中的 guid 命令集值匹配。

<GuidSymbol name="guidEfCoreCrudBootStrapPackageCmdSet" value="{5017a255-b672-4113-b19a-422a35b0af64}">
  <IDSymbol name="MyMenuGroup" value="0x1020" />
  <IDSymbol name="EfCoreCrudBootStrapCommandId" value="0x0100" />
    <IDSymbol name="MyMenuGroup" value="0x1020" />
    <IDSymbol name="SampleCommandId" value="0x0100" />
    <IDSymbol name="SampleMenu" value="0x1021"/>
</GuidSymbol>

<GuidSymbol name="guidImages" value="{14c1b0d2-fd1c-41b4-88f0-9545d5ecdf31}" >
  <IDSymbol name="bmpPic1" value="1" />
  <IDSymbol name="bmpPic2" value="2" />
  <IDSymbol name="bmpPicSearch" value="3" />
  <IDSymbol name="bmpPicX" value="4" />
  <IDSymbol name="bmpPicArrows" value="5" />
  <IDSymbol name="bmpPicStrikethrough" value="6" />
 
</GuidSymbol>

推荐阅读