Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 pages too.

Thanks -- I know someone out there has the perfect solution :).

like image 739
Buffalo Avatar asked Oct 14 '10 00:10

Buffalo


1 Answers

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

like image 54
Raymund Avatar answered Oct 02 '22 17:10

Raymund