1

Before this gets marked as duplicate, I know this question has been asked in the past [1] [2], but the answers are extremely outdated and only contain workarounds and 3rd party tools.

The exact question here would be: Is it possible to change the xml comment template generated by typing "///" in Visual Studio 2019+ without using 3rd party tools? For example, add custom tags to the template?

For example, replace:

/// <summary>
/// 
/// </summary>
/// <param name="myParam"></param>
/// <returns></returns>
public int MyMethod(string myParam) { }

with:

/// <summary>
/// 
/// </summary>
/// <param name="myParam"></param>
/// <myTag></myTag>
/// <returns></returns>
public int MyMethod(string myParam) { }
DMX David Cardinal
  • 599
  • 2
  • 7
  • 19

1 Answers1

1

Yes/No, one can create a code snippet which can give you the basic format, but getting the parameters dynamically will be problematic.

I would suggest using a hybrid method where after running the standard xml comment that the code snippet deletes (if needed) and adds more tag(s) and other items which you may need.


One line Summary

This snippet just creates <Summary> X </Summary> and deposits a user on the X to fill it out. It is one I created and actually use.

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Single line summary</Title>
      <Shortcut>summary</Shortcut>
    </Header>
    <Snippet>
      <Code Language="csharp">
        <![CDATA[/// <summary>$end$</summary>]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

Here it is in action, by just typing in summary then Tab to initiate it.

enter image description here

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
  • Yes this is also what is suggested in one of the original questions, however it does not answer the question as this doesn't modify/extend the existing template for /// nor does this method allow for the desired result – DMX David Cardinal Nov 23 '21 at 16:26
  • *Within Visual Studio*, Unless one is willing to make a Visual Studio Addin, I believe the hybrid method as mentioned is a viable alternative. GL – ΩmegaMan Nov 23 '21 at 16:33