Visual Studio 2017 extended development (1) Add a menu to the Visual Studio menu bar, visual Studio menu bar
Recently, I have been involved in the development of visual studio 2017 extensions. I hereby record it to urge myself to gain a deep understanding of its principles.
Start to develop Visual Studio extensions. Here I have installed visual studio 2017. Remember to check visual studio extension development when installing Visual Studio.
Create a project
Open the compiler, file → create a Project, template → Visual C # → Extensibility select VSIX Project. Create a Project.
Add custom commands
Right-click a project and add a new project. Visual C # item → Extensibility → Custom Command
Find the menu name for modifying the CommandPackage. vsct file.
In the Commands node.
<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 = "BMP pic1"/> <Strings> <ButtonText> test menu </ButtonText> </Strings> </Button> </Buttons>
Then open the Command. cs file. Drop down to the end.
Private void MenuItemCallback (object sender, EventArgs e) {string message = "Hello Word"; string title = "test"; // Show a message box to prove we were here VsShellUtilities. showMessageBox (this. serviceProvider, message, title, OLEMSGICON. OLEMSGICON_INFO, OLEMSGBUTTON. OLEMSGBUTTON_ OK, OLEMSGDEFBUTTON. OLEMSGDEFBUTTON_FIRST );}
Result
Run, A New Visual Studio is opened, which is the debugging mode.
Click the tool to view the expanded menu.
Click test menu
This article is only my learning record. I should continue to write it later. If it is helpful to you, move your mouse and give me a thumbs up at the bottom right. Your support is my greatest motivation.