Visual Studio 2019 VSIX插件


使用步骤

一.创建项目

图示如下(示例):

1、打开Visual Studio 2019,选择"VSIX Project"模板项目;
在这里插入图片描述
2、右击项目节点添加Command模板新增插件;
在这里插入图片描述
3、新增完毕后大致的目录如下所示;
区域 1:存放资源文件,通常存放插件的图标,大小通常为16*16;
区域 2:此处为具体所需开发插件的类(一些逻辑通常添加在此类中),有几个类就代表着相应开发插件的个数;
区域 3:此处为配置文件,插件的相关配置都在此文件夹中(插件的位置、名称、图标、快捷键等);
在这里插入图片描述

二.VSCT配置文件节点介绍

代码如下(示例):

		<!-- 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. -->

		<!--  父级菜单所在位置:
              IDM_VS_MENU_TOOLS         默认菜单工具栏   
              IDM_VS_CTXT_CODEWIN       代码文件,.cs文件在编辑器中点右键(上下文右键)
              IDM_VS_CTXT_FOLDERNODE    在文件夹上点右键
              IDM_VS_CTXT_ITEMNODE      在项目中的文件上点右键
              IDM_VS_CTXT_NOCOMMANDS    没有菜单
              IDM_VS_CTXT_PROJNODE      在项目节点上点右键
              IDM_VS_CTXT_SOLNNODE      在解决方案上点右键
              具体介绍官网:https://docs.microsoft.com/zh-cn/visualstudio/extensibility/internals/guids-and-ids-of-visual-studio-menus?view=vs-2019
              <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
			  
			  1.此时若想将插件位置放置于“项目节点右键”,只需将Parent节点中的id由“IDM_VS_MENU_TOOLS”更改为“IDM_VS_CTXT_PROJNODE”即可;
			  2.Group节点中的priority属性与插件的排序有关,0x0000排在最上方,0x0001往后以此类推;
          -->
		<Groups>
			<Group guid="guidSelfVSIXProjectPackageCmdSet" id="MyMenuGroup" priority="0x0000">
				<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_PROJNODE "/>
			</Group>
		</Groups>


		<!--Buttons section. -->
		<!--This section defines the elements the user can interact with, like a menu command or a button
        or combo box in a toolbar. -->
		<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="guidSelfVSIXProjectPackageCmdSet" id="MySelfCommand1Id" priority="0x0100" type="Button">
				<!--  父类菜单位置  -->
				<Parent guid="guidSelfVSIXProjectPackageCmdSet" id="MyMenuGroup" />
				<!--Icon相关配置,若不想显示icon,可直接将icon节点删除-->
				<Icon guid="guidImages" id="bmpPic1" />
				<Strings>
					<!--  显示的名称  -->
					<ButtonText>Invoke MySelfCommand1</ButtonText>
				</Strings>
			</Button>
		</Buttons>


		<!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
		<Bitmaps>
			<!--  The bitmap id is defined in a way that is a little bit different from the others:
            the declaration starts with a guid for the bitmap strip, then there is the resource id of the
            bitmap strip containing the bitmaps and then there are the numeric ids of the elements used
            inside a button definition. An important aspect of this declaration is that the element id
            must be the actual index (1-based) of the bitmap inside the bitmap strip. -->
			<!-- 配置图片资源信息 -->
			<Bitmap guid="guidImages" href="Resources\MySelfCommand1.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
		</Bitmaps>

三.在项目右击节点上新增自定义插件

1、根据以上介绍,此时更改Groups=>Group=>Parent节点中的id更改为“IDM_VS_CTXT_PROJNODE”即可将插件显示于项目右击节点上

        <Groups>
			<Group guid="guidSelfVSIXProjectPackageCmdSet" id="MyMenuGroup" priority="0x0000">
				<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_PROJNODE "/>
			</Group>
		</Groups>

2、删去图标显示,将Icon节点注释即可;

			<Button guid="guidSelfVSIXProjectPackageCmdSet" id="MySelfCommand1Id" priority="0x0100" type="Button">
				<!--  父类菜单位置  -->
				<Parent guid="guidSelfVSIXProjectPackageCmdSet" id="MyMenuGroup" />
				<!--Icon相关配置,若不想显示icon,可直接将icon节点删除-->
				<!-- <Icon guid="guidImages" id="bmpPic1" /> -->
				<Strings>
					<!--  显示的名称  -->
					<ButtonText>Invoke MySelfCommand1</ButtonText>
				</Strings>
			</Button>

3、配置更改完成后,运行当前实例(F5),在实例中打开一个项目,如图可以看到最终效果
在这里插入图片描述


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值