Keyboard: CTRL + SHIFT + R (record/stop recording); CTRL + SHIFT + P (run)
Menu: Tools -> Macros -> Record Temporary Macro; Tools -> Macros -> Run Temporary Macro; Tools -> Macros -> Save Temporary Macro
Command: Tools.RecordTemporaryMacro; Tools.RunTemporaryMacro; Tools.SaveTemporaryMacro
You can record macros to do just about anything in Visual Studio. In this example, we will create a macro that adds a new class to our project. First, create a new project. For this example create a Console Application:
Now we are going to add a class to the project and give the class a name. When we do this, we will record the actions into a temporary macro. Press CTRL + SHIFT + R to begin recording our macro. You will know you are recording if the status bar indicates it in the lower left-hand corner:
Add a new class (CTRL + SHIFT + A) called “Bubba.cs”:
DANGER: There are lots of little “gotchas” that you will run into doing macros. One that took me a little while to figure out while doing this example was leaving off the “.cs” at the end of the file name. For some reason it doesn’t like that at all. Keep an eye out for little things like that as you use this feature.
Now add a comment to the class:
Now stop recording (CTRL + SHIFT + R) then go to Tools -> Macros -> Save Temporary Macro. Name the macro “MakeBubba” in the Macro Explorer:
That’s it. Now we can test out our new macro by creating a new project and going to the Macro Explorer (ALT + F8). Then RIGHT CLICK the MakeBubba macro and choose “Run”:
It should make the new class and put your comment in:
Once you have created your macro you might want to see the code behind it, you can go to the Macro Explorer (ALT + F8) and RIGHT CLICK any macro then choose “Edit” to see the code. Here is what my code (cleaned up a bit) looks like for the macro we just made:
Notice it is fairly easy to read and understand which makes it easy to edit as well. Now that you have a working macro you should visit vstipTool0066 (http://blogs.msdn.com/b/zainnab/archive/2010/08/07/create-a-shortcut-key-for-a-macro-vstiptool0066.aspx) and create a shortcut key for it.