VS2010: Automatically insert date and initials to single line comments
Greetings Friends,
What is the best way (least amount of keystrokes) to get Visual Studio 2010 to automatically insert the current date and my name/initials whenever I put a single line comment into my codebase? This should support C# and it'd be even better if it worked in my .aspx pag开发者_开发知识库es too.
Thanks -- I know someone out there has the perfect solution :).
Create a macro and assign a Shortcut key.
The easiest way is go to Tools->Macros->Macro Explorer and edit one of the samples, I used Samples->VSEditor, right click that one and edit. Now youre in the Macro editor Now create this function.
Sub NewCommentLinePersonal()
Dim textSelection As EnvDTE.TextSelection
textSelection = DTE.ActiveWindow.Selection
textSelection.NewLine()
textSelection.Insert(Utilities.LineOrientedCommentStart())
textSelection.Insert(" " + Date.Now + " - Your Initial ")
End Sub
then go to Tools->Options->Environment->Keyboard
and type the NewCommentLinePersonal
on textbox "Show commands containing:" then choose your shortcut key
Perhaps another way of approaching it, assuming the insertion of a timestamp and name is being done for change tracking, is to lean on source control.
For example, in my current codebase, we deprecated the use of putting in change comments, since we found that the field of green was cluttering things, and if I ever needed to see who changed what, I could simply look in our source control system, and even see how this one change was related to other modifications within the same changeset.
精彩评论