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:
-
In Visual Studio, Go to Tools->Macros->Macro Explorer or press "Alt-F8"
-
In the Macro Explorer, right-click RecordingModule and select "Edit"
-
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
-
Exit out of the "Microsoft Visual Studio Macros" window
-
In Visual Studio, Go To Tools->Options. Under the "Environment" Heading, go to the "Keyboard" option.
-
In the "Show Command Containing" textbox, enter "Macros.MyMacros"
-
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"
-
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.
For more information about .NET macros, please see the following MSDN articles: