zoukankan      html  css  js  c++  java
  • visual Studio 2017 扩展开发(一)《向Visual Studio菜单栏新增一个菜单》

    最近有接触到关于visual studio 2017 扩展的开发,特此记录,也是为了督促自己去深入了解其原理。

    开始开发Visual Studio 扩展,在这里我安装了visual studio 2017, 在安装的时候记得勾选上visual studio 扩展开发。

    创建一个项目

    我们打开编译器,文件→新建项目,模板→Visual C#→Extensibility 选择 VSIX Project.创建一个项目。

    添加自定义命令

    右键项目,添加新项。Visual C#项→Extensibility→Custom Command

    我们找到CommandPackage.vsct文件 修改菜单名。

    在Commands节点下的Buttons。

    <Buttons>
          <!--To define a menu group you have to specify its ID, the parent menu and its display priority.
              The command is visible and enabled by default. If you need to change the visibility, status, etc, you can use
              the CommandFlag node.
              You can add more than one CommandFlag node e.g.:
                  <CommandFlag>DefaultInvisible</CommandFlag>
                  <CommandFlag>DynamicVisibility</CommandFlag>
              If you do not want an image next to your command, remove the Icon node /> -->
          <Button guid="guidCommandPackageCmdSet" id="CommandId" priority="0x0100" type="Button">
            <Parent guid="guidCommandPackageCmdSet" id="MyMenuGroup" />
            <Icon guid="guidImages" id="bmpPic1" />
            <Strings>
              <ButtonText>测试菜单</ButtonText>
            </Strings>
          </Button>
        </Buttons>

    再打开Command.cs文件。下拉到最后。

            private void MenuItemCallback(object sender, EventArgs e)
            {
                string message = "Hello Word";
                string title = "测试";
    
                // Show a message box to prove we were here
                VsShellUtilities.ShowMessageBox(
                    this.ServiceProvider,
                    message,
                    title,
                    OLEMSGICON.OLEMSGICON_INFO,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }

    结果

    运行,会打开一个新的Visual Studio,这是调试模式。

    点开工具 我们可以看到我们扩展的那个菜单。

    点击测试菜单

    此随笔仅是本人学习记录,后续应该会继续写,如果对你有帮助,动动你的鼠标,右下方给我来个赞。你的支持是我最大的动力。

  • 相关阅读:
    【CV论文阅读】Detecting events and key actors in multi-person videos
    2020意大利数学奥林匹克 第6题
    2020最终数学杯 初级组第3题
    地球上的最短距离
    钱学森做过的趣题
    第35届IMO预选题(瑞典提供)
    第55届IMO 第2题
    第四十届(1999年)IMO 第3题(白俄罗斯供题)
    2019年多瑙河数学竞赛(高中组) 第三题
    2020环球城市春季赛 O级别 高级组 第2题
  • 原文地址:https://www.cnblogs.com/huangenai/p/7182284.html
Copyright © 2011-2022 走看看