Microsoft finally got rid of macros in Visual Studio 2012. An attempt was made in VS 2010 beta, but under the pressure of outraged users, macros returned to release. In VS 2012 they disappeared completely. I think Microsoft had good reasons for this, but for users who are not indifferent to this topic, this caused the opposite emotions from delight. The ability to put some kind of macro on the fly (quite often one-time), without resorting to creating an extension, was very valuable. And for those who, during the past studios, wrote a lot of useful macros for themselves, the transition to VisualStudio 2012 is quite problematic.
Task : transfer files with macros to AddIn to enable their use in VS 2012 both with hot keys and in the menu.
As a result of solving the problem, a project template appeared, in which it is enough to add files with your macros, compile and copy to the My Documents \ VisualStudio 2012 \ AddIns folder. Download the project - Dropbox . ')
Module transfer
In Visual Studio 2010(or earlier), open the macro editor. In the Project Explorer window, select our modules, right-click, and select Export ... and save them.
Open the loaded project in Visual Studio 2012 . Right-click on the Cmd folder, click Add \ Existing Items and select the saved files.
Each module is wrapped in Namespace Cmd , from which a selection of commands will be made.
Namespace Cmd .... End Namespace
Helper classes and modules, it is better to place in another folder, for example in Helpers .
Basic settings. Module " g.vb "
To specify a list of commands that need to be displayed in the menu, fill in the cmdIcons collection. Format: {'' Module_Name. Procedure_Name '', icon number (FaceID) from Microsoft Office Toolbar}. Example:
Friend cmdIcons As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer) From { ... , {"Sample.Test", 917} }
The variable MyMenuName indicates in which menu to display the list of commands from cmdIcons . At the moment, it is worthwhile to indicate the name from the existing list of the main menu. When you specify a different name, it is displayed only when you first start it; on subsequent ones it disappears along with the list. I would be glad if someone helps in solving this problem.
If necessary, fill in the document events:
PrivateSub document_Saved(ByVal d As EnvDTE.Document) Handles docEvents.DocumentSaved ' End Sub Private Sub document_Open(ByVal d As EnvDTE.Document) Handles docEvents.DocumentOpened ' End Sub Private Sub document_Close(ByVal d As EnvDTE.Document) Handles docEvents.DocumentClosing ' End Sub
Final stage
Compile the project, open the bin folder and copy the files MyAddin.AddIn , MyAddin.dll in My Documents \ Visual Studio 2012 \ AddIns .
If the project has been renamed, then you must also rename the file MyAddin.AddIn and change its interior according to the new name.
Restart VisualStudio.
Go to Tools \ Options \ Environment \ Keyboard type in search MyAddin (or what they renamed) and assign hotkeys.
Notes
In macros, access to the IDE was made via the DTE variable, a global variable with the same name and corresponding link was already created in the g.vb module, so you do not need to change anything in the macros.
For convenience, the Selection property ( pointing to the selected text in the document ) and the Doc property ( indicating the active document ) are placed in g.vb, which you can access from your macros via g.Selection and g.Doc.
After recompiling the project and updating the files in the Visual Studio 2012 \ AddIns folder, your macros will need to be assigned the hotkeys.
PS: I will be glad to constructive criticism and suggestions.