Good day.
We will create a Visual Studio extension that embeds the “Create C ++ Header #define” field into the context menu of the editor, when clicking on which the unique
#define directive is generated (the directive allows the header to be included only once).
Ultimately, it will look like this:

In fact, this is usually automated with the help of the studio's macros (and there are a lot of macro options on the network), but it is more pleasant for me to use the context menu, especially as creating the extension itself is simple, VSPackage Builder will do all the work, we will only have to enter a few lines. code in the click handler menu item.
')
So, let's begin. We will need Visual Studio 2010 Pro or later. It is necessary to additionally install the
Visual Studio 2010 SDK and the special
VSPackage Builder add-
on to make the creation of new extensions as easy as possible.
Creating an extension
Create a new project in Visual Studio:
Visual C # -> Extensibility -> VSPackage BuilderWe give the project a name - I called it HeaderDefineCreater.

In the opened project we will place on the designer of the extension (file HeaderDefineCreater.vspackage) all the elements we need. Let's start with the first element - add a context menu. In its properties opposite the Location field, select the location - “Context Menu | Editor

Then create a Group, one button (let's call it CreateHeaderDefineButton) and two connections between all the elements. The screenshot on the left side shows the properties for the button. Everything is standard there, except it should be noted that the button (that is, the line in the context menu) will be visible only in the editor (
Visibility Constraints: TextEditor ). As for the shortcut, these fields can be left blank, since they can be configured separately when using the extension.

Well, everything is ready. It remains only to fill the click handler on the context menu item.
The automatically generated click handler looks like this:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.OLE.Interop; using Microsoft.VisualStudio.Shell; namespace HeaderDefineCreater { [Guid(GuidList.guidHeaderDefineCreaterPkgString)] public class HeaderDefineCreaterPackage : HeaderDefineCreaterPackageBase { protected override void CreateHeaderDefineButtonExecuteHandler(object sender, EventArgs e) { } } }
Fill the handler. There are many similar macros for the studio, written in VB, so I didn’t have to invent anything myself, I just rewrote it a bit in C #.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.OLE.Interop; using Microsoft.VisualStudio.Shell;
It only remains for us to fill in the fields in the manifest (add an icon, a description, etc.) and compile everything.

After compilation we will get a ready extension HeaderDefineCreater.vsix.
Installing extensions and changing shortcuts
The extension is installed by a simple double click.
You can remove it by going to
Tools-> Extension Manager .

In order to install a shortcut for an extension, go to
Tools -> Options -> Keyboard , find the button name there by searching (we called the button CreateHeaderDefineButton, but, for simplicity, we could call it the name of the extension). For the found button, we put any free combination:

Thanks for attention. Comments are welcome. I note that I do not write in C #, but I study C ++ and the extension was created primarily to facilitate routine operations on the pros and for internal use. I think that the name for the field of the context menu could be thought up better ... and the icon does not match the content :) But here I just wanted to show how quickly I can create my extension, I hope someone else will be useful.
I did not publish the entire project here, because the extension is very simple, all the steps are described, and all the code in the click handler is also posted here. Therefore, I will apply for example only the extension itself, which is the result -
HeaderDefineCreater.vsix