90

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?

5
  • 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? Commented Dec 14, 2015 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 Commented Dec 14, 2015 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? Commented Dec 14, 2015 at 19:54
  • stackoverflow.com/questions/9481303/… Commented Dec 14, 2015 at 19:55
  • 3
    To be clear: I am using Visual Studio Code(code.visualstudio.com), not the regular visual studio. Commented Dec 14, 2015 at 19:57

3 Answers 3

92

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,
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the update - this saved me a bit of time.
I was looking for this setting under C#. Thank you.
In Mac it is under Code/Preferences/Settings/Text Editor/Formatting
55

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

1 Comment

That extension is deprecated as it is built in to the C# for Visual Studio Code extension (see Pascal's answer)
5

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

4 Comments

Sorry this did not work, even after a complete un-install of VSCode, and Completely uninstall VS Code extensions (code --list-extensions: ms-dotnettools.csdevkit; ms-dotnettools.csharp; ms-dotnettools.vscode-dotnet-runtime; ms-vscode-remote.remote-wsl / code --version: 1.90.0)
it was working until last week and stopped working now. I tried all the methods mentioned in this thread.
Agreed. Something broke within the past couple days.
still not working with 1.95.3 (Windows)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.