开发者

Extension to append username and date to Visual Studio 2010 code comment

开发者 https://www.devze.com 2023-02-19 19:28 出处:网络
Is there an Visual Studio 2010 extension that would allow you to insert comments and automatically append your username and current date:

Is there an Visual Studio 2010 extension that would allow you to insert comments and automatically append your username and current date:

// You type comments here [by Toni, on 03/开发者_StackOverflow26/2011]

It would help us to maintain uniform comments format in our solution.

Edit: This question is not about VCS, I am aware you can add and enforce comments there. I am just looking for Visual Studio 2010 Client only solutions!


That should be handled by your version control system since it's more a code metadata than a code itself. Leaving it in code may lead to more troubles than taking from VCS in case if somebody will update a comment but will forget to update an author. Most modern VCS have blame command (see SVN blame for example) which will show the revision and author of that comment line.


I tend to agree with snowbear that keeping track of who wrote what code belongs in source control. If for whatever reason it makes more sense for your group to have the comments in the code, then you could probably get away with just creating a visual studio macro and tieing it up to a hotkey. Something like the following should suffice:

Sub TaggedComment()
    DTE.ActiveDocument.Selection.Text = "//   [by "
    DTE.ActiveDocument.Selection.Text = Environment.UserName
    DTE.ActiveDocument.Selection.Text = ", on "
    DTE.ActiveDocument.Selection.Text = DateTime.Now.Date.ToShortDateString
    DTE.ActiveDocument.Selection.Text = "]"
    DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
    DTE.ActiveDocument.Selection.CharRight(False, 3)
End Sub

Alternatively, you could look at creating a Code Snippet instead (which seems to be the more performant solution).


Have you looked at LogSubstPol on codeplex?

I quote:

LogSubstPol is a TFS check-in policy which inserts the check-in comments and other keywords into your source code, so you can keep track of the changes even if you are not connected to TFS. It can be compared with the $log$ (and other) substitition in any other CVS systems.

Otherwise, you can write your own :-) It should be based on TFS checkin policy extensibility, using the PolicyBase Class

0

精彩评论

暂无评论...
验证码 换一张
取 消