86

In MonoDevelop, when I type "///", it auto-generates an xml-style comment like this:

/// <summary>
/// Describes the variable x
/// </summary>
int x = 0;

Is there a way to get this behavior in Visual Studio Code?

femtoRgon
  • 32,893
  • 7
  • 60
  • 87
s2Jakob
  • 861
  • 1
  • 6
  • 3
  • 3
    By default, looks like that doesn't work for local variables. /// works for method signatures and class properties though. Do you really comment local variables? – Andy Wiesendanger Dec 14 '15 at 19:43
  • There is no a practical use for this, you can do this in Visual studio with all properties and methods, if it is a local varialbe then just a comment (//) should be enough – bto.rdz Dec 14 '15 at 19:54
  • That's weird. For me, it doesn't work for methods or properties. Is there maybe a setting I need to change? – s2Jakob Dec 14 '15 at 19:54
  • http://stackoverflow.com/questions/9481303/enabling-triple-three-slash-xml-comments-in-visual-studio-2010-for-c-sharp – Andy Wiesendanger Dec 14 '15 at 19:55
  • 3
    To be clear: I am using Visual Studio Code(https://code.visualstudio.com/), not the regular visual studio. – s2Jakob Dec 14 '15 at 19:57

3 Answers3

89

Starting with C# for Visual Studio Code Extension 1.23.8 this is supported when Editor: Format On Type. setting is enabled.

Settings can be found in the menu under File/Preferences/Settings (Windows/Linux) / Code/Preferences/Settings (macOS).

The required setting is available under Text Editor/Formatting.

{
    "editor.formatOnType": true,
}
KyleMit
  • 30,350
  • 66
  • 462
  • 664
Pascal Berger
  • 4,262
  • 2
  • 30
  • 54
54

This feature is not available out-of-the-box with VS Code, but like most features is available via third-party extensions. As of the time of this answer, here is a popular extension that provides some XML comments support to VS Code:

C# XML Documentation Comments Support for Visual Studio Code

If that extension doesn't work for you, you may be able to find alternatives by searching the VS Code Marketplace

Aejay
  • 909
  • 9
  • 19
Keisuke KATO
  • 1,509
  • 1
  • 16
  • 26
  • That extension is deprecated as it is built in to the C# for Visual Studio Code extension (see [Pascal's answer](https://stackoverflow.com/a/65716253/8804293)) – Elijah Mock Oct 02 '22 at 21:26
3

You can set this just for c# if you use Visual Studio Code for other languages as well:

  • Open the command palette and search for Configure Language Specific Settings

enter image description here

  • Select C# and search for Format On Type

enter image description here

Docs

JayChase
  • 11,174
  • 2
  • 43
  • 52