不积跬步,无以至千里;不积小流,无以成江海。

Dean's blog

  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

Visual Studio 2017扩展开发

安装

安装VS2017并选择Visual Studio 扩展开发。

创建插件项目

选择“Extensibility - VSIX Project”项目类型

添加自定义菜单 

添加新项时选择“Extensibiliy - Custom Command”,并命名为HelloWord。

添加后,VS会创建一系列文件:

我们修改其中的vsct文件,找到<Buttons>节点,并修改<ButtonText>,这个用于在菜单上的显示:

    <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="guidHelloWordPackageCmdSet" id="HelloWordId" priority="0x0100" type="Button">
        <Parent guid="guidHelloWordPackageCmdSet" id="MyMenuGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>你好!</ButtonText>
        </Strings>
      </Button>
    </Buttons>

 

打开HelloWord.cs文件,找到private void Execute(object sender, EventArgs e)方法:

private void Execute(object sender, EventArgs e)
{
    ThreadHelper.ThrowIfNotOnUIThread();
    string message = "简单测试";
    string title = "HelloWord";

    // Show a message box to prove we were here
    VsShellUtilities.ShowMessageBox(
        this.package,
        message,
        title,
        OLEMSGICON.OLEMSGICON_INFO,
        OLEMSGBUTTON.OLEMSGBUTTON_OK,
        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
}

运行测试

以Debug模式,直接运行测试,它会重新打开一个VS并安装这个按钮到“工具”菜单下:

点击后的效果:

不允许评论
粤ICP备17049187号-1