Question

When I type the trigger the auto comment feature in Visual Studio (by typing "'''" or "///"), most of the XML commenting details show up that I like. However, I typically add the history tag to the documentation so I can track and changes that are made to the method over time.

Is there any way I can customize the auto commenting feature so that it will add the history tag, and potentially some generic Name - Date - Change placeholder text?

Was it helpful?

Solution

I'd suggest using GhostDoc. It generates very smart comments using /// based on your method names and parameters. Also, it is fully customizable.

OTHER TIPS

I think that you could use a tool as dgarcia said but try to chose one that makes the version control insetad, Personally I'm not a huge fan of keep the "history" or track of the project using comments in the code.

If you like that way you could create your own customized version of the snippet, this is easier if you use a tool like Snippy

Copy this file to your

My Documents\Visual Studio 2005\Code Snippets[Language]\My Code Snippets\

Just be carefull to change the file if you gonna use it in VB.NET

Hope this help

Just as followup to the comment to Olivier. Here is a copy of the macro now, look for the '' Do History section to see where I inserted code.

    ''// InsertDocComments goes through the current document using the VS Code Model
    ''// to add documentation style comments to each function.
    ''
    Sub InsertDocComments()
        Dim projectItem As ProjectItem
        Dim fileCodeModel As FileCodeModel
        Dim codeElement As CodeElement
        Dim codeElementType As CodeType
        Dim editPoint As EditPoint
        Dim commentStart As String

        projectItem = DTE.ActiveDocument.ProjectItem
        fileCodeModel = projectItem.FileCodeModel
        codeElement = fileCodeModel.CodeElements.Item(1)

        ''// For the sample, don't bother recursively descending all code like
        ''// the OutlineCode sample does. Just get a first CodeType in the
        ''// file.
        If (TypeOf codeElement Is CodeNamespace) Then
            codeElement = codeElement.members.item(1)
        End If
        If (TypeOf codeElement Is CodeType) Then
            codeElementType = CType(codeElement, CodeType)
        Else
            Throw New Exception("Didn't find a type definition as first thing in file or find a namespace as the first thing with a type inside the namespace.")
        End If

        editPoint = codeElementType.GetStartPoint(vsCMPart.vsCMPartHeader).CreateEditPoint()

        ''// Make doc comment start.
        commentStart = LineOrientedCommentStart()
        If (commentStart.Length = 2) Then
            commentStart = commentStart & commentStart.Chars(1) & " "
        ElseIf (commentStart.Length = 1) Then
            commentStart = commentStart & commentStart.Chars(0) & commentStart.Chars(0) & " "
        End If

        ''// Make this atomically undo'able.  Use Try...Finally to ensure Undo
        ''// Context is close.
        Try
            DTE.UndoContext.Open("Insert Doc Comments")

            ''// Iterate over code elements emitting doc comments for functions.
            For Each codeElement In codeElementType.Members
                If (codeElement.Kind = vsCMElement.vsCMElementFunction) Then
                    ''// Get Params.
                    Dim parameters As CodeElements
                    Dim codeFunction As CodeFunction
                    Dim codeElement2 As CodeElement
                    Dim codeParameter As CodeParameter

                    codeFunction = codeElement
                    editPoint.MoveToPoint(codeFunction.GetStartPoint(vsCMPart.vsCMPartHeader))
                    ''//editPoint.LineUp()
                    parameters = codeFunction.Parameters

                    ''// Do comment.
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.LineUp()
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "<summary>")
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "Summary of " & codeElement.Name & ".")
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "</summary>")
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart)

                    For Each codeElement2 In parameters
                        codeParameter = codeElement2
                        editPoint.Insert("<param name=" & codeParameter.Name & "></param>")
                        editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                        editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart)
                    Next ''//param

                    ''// Do history tag.
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.LineUp()
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "<history>")
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "Name   MM/DD/YYYY   [Created]")
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "</history>")
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart)

                End If ''//we have a function
            Next ''//code elt member

        Finally
            DTE.UndoContext.Close()
        End Try
    End Sub

For some reason, after a save, rebuild, and a restart of Visual Studio, I'm not getting the history tag. Can anybody see something here I'm missing?

vb uses a xml file to load the defults. It is VBXMLDoc.xml and it depends on what version you are running as to the location of the file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top