locked
Customizing the default XML comments tag

    Question

  • Currently when we type /// just above a function name like "public void foo()"

    We get the following auto generated code
    /// <summary>
    ///
    /// </summary>
    public void foo()


    Is there any way to customize this to add the current user name and the date? I would like to see something like
    /// <summary>
    ///
    /// </summary>
    /// <author> Bill Gates </author> <date> 10.10.08 </date>


    Thanks



    Thursday, March 06, 2008 8:02 PM

Answers

  • Hi,

    As far as I know, it is not possible to change the text automatically inserted when entering three slashes. I needed this in another project I was on, and I solved it by adding a snippet with the text I needed. That way at least all the tags I needed for the XML documentation were always present. I guess you can go and add some other information in there as well...


    Keeping dates and users in comments might be counter productive. If the comment is already there, are all your developers going to update the information if they changed anything? Chances are a good source control solution can provide you with all the information you need about versions of methods and the changes a certain user made to code.

    Hope this helps.

    Friday, March 07, 2008 12:36 PM

All replies

  • Hi,

    As far as I know, it is not possible to change the text automatically inserted when entering three slashes. I needed this in another project I was on, and I solved it by adding a snippet with the text I needed. That way at least all the tags I needed for the XML documentation were always present. I guess you can go and add some other information in there as well...


    Keeping dates and users in comments might be counter productive. If the comment is already there, are all your developers going to update the information if they changed anything? Chances are a good source control solution can provide you with all the information you need about versions of methods and the changes a certain user made to code.

    Hope this helps.

    Friday, March 07, 2008 12:36 PM
  • Hi,

    Let me throw in an example:

    Code Snippet
    <?xml version="1.0" encoding="utf-8" ?>
    <CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
     <CodeSnippet'>http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
     <CodeSnippet Format="1.0.0">
      <Header>
       <Title>Custom comment</Title>
       <Shortcut>cmnt</Shortcut>
       <Description>Code snippet for a custom comment block</Description>
       <Author>Rick van den Bosch</Author>
       <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
       </SnippetTypes>
      </Header>
      <Snippet>
       <Code Language="csharp"><![CDATA[///<summary>
     ///
     /// </summary>
     /// <Author></Author>
     /// <DateTime></DateTime>]]>
       </Code>
      </Snippet>
     </CodeSnippet>
    </CodeSnippets>

     

     

    Put this in a file, call it Comment.snippet (or any other name, as long as it ends in .snippet) and put it in your snippet directory ( My Documents\Visual Studio 2005\Code Snippets\Visual C#\My Code Snippets\ ). Type in the shortcut (in this case cmnt) in VS text editor and hit tab: there you go!

    Hope this helps!

    Friday, March 07, 2008 12:52 PM
  • This is what you're looking for.

    http://blog.developers.ie/cconnolly/archive/2006/11/04/2515.aspx


    Collin Sauve
    • Proposed as answer by Collin Sauve Tuesday, February 10, 2009 8:29 PM
    Tuesday, February 10, 2009 8:28 PM
  • This customization works only for Visual Basic.

    Do you know how to make it work for C#?

    Thursday, March 22, 2012 8:36 PM
  • This customization works only for Visual Basic.

    Do you know how to make it work for C#?


    This is only available for Visual Basic.

    Here you can vote to have the feature included for C# too:

    http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2709987-xml-comments-schema-customization-in-c-

    Friday, March 23, 2012 7:37 PM