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,这是调试模式。

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

 

点击测试菜单

 

 

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值