Visual Studio Macros increase productivity

by Arnold Matusz 8 1 2009

Most .NET developers write their code in a Visual Studio IDE. There are several reasons to use Visual Studio, but only few people really explore more advanced features than the basic controls / windows: Solution Explorer, Class View, Model Browser, Toolbox, Find and Replace :).

This is why I' ld like to take the opportunity to write about Visual Studio Macros for those of you who haven't had the chance meet Macros until now.

What are Visual Studio Macros?
Visual Studio Macros are series of commands and instructions grouped together as a single command to accomplish a task automatically, hence Macros are useful when repetitive actions are taking place. Visual Studio includes the Macros integrated development environment (IDE), which is used solely for creating, manipulating, editing, and running macros. The Macros IDE is separate from the Visual Studio IDE. (Check MSDN for reference)

Why do I need to use Visual Studio Macros?
Macros come in handy whenever you need to work through repetitive tasks within your Visual Studio IDE or when your task can be automated. To get the idea I'll explain a situation where a snippet provided by Microsoft fitted in perfectly.

Every now and then there might be 2 separate approaches when tackling a task, so you might want to try the second out after having implemented the first approach. (What I normally do in ASP.NET is, I create a backup file for the aspx file and the cs/vb file and then I edit my page for the second approach.)  Why should I use Save As and type in some name and extensions manually when there is a Macro which can do all of this for me at the touch of a button, I mean at the run of a Macro.
In your Macro Explorer (Alt+F8 to bring it up) double-click SaveBackup from Samples -> VSEditor -> SaveBackup. To check what has happened, please verify the folder which the currently open document sits in and search for your filename with a .bak extension.

What you need to know to write a Macro?
The first thing you need to be aware of is that Macros are written in VB language, so you should know some basic programming in Visual Basic. By recording a new macro you can learn how macros actually work, so the best way forward to is to get down and dirty and so some tests. Don't get frightened about recording macros, it's the another word for recording the exact function calls which are fired when you use the Visual Studio IDE.

What about some samples?
I'm glad to tell you that Visual Studio ships with many macro samples. There are many Macros you can run while debugging: BreakpointLastHit, BreakpointLastHit (yes I know there is a keyboard shortcut for this), DumpStacks, ListAllBreakpoints, StepOverAll, etc.

Also worth mentioning are the Utilities macros with the samples provided by Microsoft: TurnOnLineNumbers, TurnOffLineNumbers, TurnOnWordWrap, TurnOffWordWrap, ListModifiedDocuments (list of all unsaved documents currently open in your IDE).

What I've also found particularly interesting is the set of macros within VSEditor (in the samples provided by Microsoft): BeginningOfFunction, CountOccurrences (counts occurrences of an input text, very useful before Find/Replace), OutLineCode (closes all function braces except the one you are currently in, very useful if there are many small functions in the same region).

What you could use Macros for?
Here's a little application idea! Code Metrics is only available in Team Edition of Visual Studio 2008. Why not write a macro which counts the number of lines of each source file in the current project / solution and then sum.

Macros have a really wide usage area taking it's rich API into consideration. The most important factor is that by using Visual Studio Macros in a well targeted manner you reduce development time, hence increase productivity.

And never forget, DRY (don't repeat yourself).

DZone it Digg it Submit to StumbleUpon Submit to Technorati Submit to Submit to Submit to NewsVine Submit to Furl Submit to BlinkList

Tags: , ,

ASP.NET | Visual Studio | .NET


1/8/2009 11:04:12 AM #

Dan Morphis

I wrote a blog post on using macros in VS to increase productivity about 2 yrs ago.  Was even linked to by Scott Guthrie!

Dan Morphis United States |

1/8/2009 4:10:08 PM #


Trackback from

Visual Studio Macros increase productivity |

1/8/2009 4:12:17 PM #


Trackback from Web Development Community

Visual Studio Macros increase productivity

Web Development Community |