Blog

.NET Commenting Macro

.NET Commenting Macro

At DMC, one of our core values is to "Share Information". Sharing information is critical while working with other engineers on many projects, including projects that use our Microsoft Visual Studio .NET skill set.

One way we communicate with each other is by adding comments into source code when making changes - it creates a visual record that is useful in determining when and why a change was made. However, it can become tedious to manually enter comments with my initials and today's date, like "// DWS 2009-07-17 - ". Fortunately Microsoft had made it easy to add macros to Visual Studio 2005 and Visual Studio 2008 to automate the creation of a date-time stamp like the one shown above.

Here is a step-by-step process on how to create a macro that will add a date-time stamp like the one shown above:

  1. In Visual Studio, Go to Tools->Macros->Macro Explorer or press "Alt-F8"

    Macro Explorer

  2. In the Macro Explorer, right-click RecordingModule and select "Edit"

  3. Add the following Sub inside "RecordingModule", inserting your own initials into the text:

    Sub CommentInitialsDate()
    	DTE.ActiveDocument.Selection.Text = "// [INSERT MY INITIALS HERE] " & Format(Date.Today, "yyyy-MM-dd") & " - "
    End Sub
    
  4. Exit out of the "Microsoft Visual Studio Macros" window

  5. In Visual Studio, Go To Tools->Options. Under the "Environment" Heading, go to the "Keyboard" option.

  6. In the "Show Command Containing" textbox, enter "Macros.MyMacros"

  7. Select the "Macros.MyMacros.RecordingModule.CommentInitialsDate" and assign a keyboard shortcut to it by hitting the keys in the "Press Shortcut Keys" dialog and hit "Assign"

  8. I would recommend the keyboard shortcuts "Ctrl-K, Ctrl-T" or "Ctrl-K, Ctrl-E" as they are not used in Visual Studio 2005 or 2008.

    Visual C# Macros

For more information about .NET macros, please see the following MSDN articles:

Comments

Srivatsa
# Srivatsa
Neat !!
Thanks a lot

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above:

Related Blog Posts