
Import Macros in Visual Studio 2012
Microsoft finally got rid of macros in Visual Studio 2012. An attempt was made back in VS 2010 beta, but under the pressure of indignant users, the macros returned to the release. In VS 2012 they disappeared completely. I believe Microsoft had good reasons for this, but for users who were not indifferent to this topic, it caused emotions opposite from delight. The ability to throw some kind of macro on the fly (quite often one-time), without resorting to creating an extension, was very valuable. And for those who have written a lot of useful macros over the past studios, switching to VisualStudio 2012 is quite problematic.
Objective : transfer files with macros to AddIn to be able to use them 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.
Downloading the project - Dropbox .
PS: I will be glad to constructive criticism and suggestions.
Objective : transfer files with macros to AddIn to be able to use them 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.
Downloading the project - Dropbox .
Module transfer
- In Visual Studio 2010 (or earlier), we open the macro editor. In the Project Explorer window , select our modules, right-click, and select Export ... and save them.
- Open the downloaded project in Visual Studio 2012 . Right-click on the Cmd folder , click Add \ Existing Items and select the saved files.
- We wrap each module in Namespace Cmd , it will select commands from it.
Namespace Cmd .... End Namespace
- Helper classes and modules are better placed in another folder, for example, in Helpers .
Basic settings. Module " g.vb "
- To specify the list of commands that need to be displayed in the menu, we fill in the cmdIcons collection .
Format: {'' Module_name. Procedure_name '', icon number (FaceID) from the Microsoft Office Toolbar}. Example:Friend cmdIcons As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer) From { ... , {"Sample.Test", 917} }
You can select the icons at this link - The MyMenuName variable indicates in which menu the list of commands from cmdIcons is displayed .
At the moment, it is worth specifying a name from the existing list of the main menu. If you specify a different name, it is displayed only at the first start, while on subsequent disappears along with the list. I would be glad if anyone helps in solving this problem. - If necessary, fill in the document events:
Private Sub 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
- We compile the project, open the bin folder and copy the files MyAddin.AddIn , MyAddin.dll
to My Documents \ Visual Studio 2012 \ AddIns . - If the project has been renamed, then you also need to rename the file MyAddin.AddIn and change its interior according to the new name.
- Restarting VisualStudio.
- Go to Tools \ Options \ Environment \ Keyboard, enter MyAddin in the search (or whatever you renamed) and assign hot keys.
Notes
- In macros, the IDE was accessed through the DTE variable , a global variable with the same name and the 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 ( indicating the selected text in the document ) and the Doс property ( indicating the active document ) are placed in g.vb , which you can access from your macros through g.Selection and g.Doc.
- After recompiling the project and updating the files in the Visual Studio 2012 \ AddIns folder, the assignment of hotkeys to your macros will have to be repeated.
PS: I will be glad to constructive criticism and suggestions.