Enabling XML Auto Commenting C# in Visual Studio Code is in an odd setting (via Stack Overflow)
Posted by jpluimers on 2025/03/18
In Visual Studio Code I already had [Wayback/Archive] C# – Visual Studio Marketplace: C# for Visual Studio Code (powered by OmniSharp) installed in (through code --install-extension ms-dotnettools.csharp), and wanted automatic XML documentation comments generation just like Visual Studio does:
[Wayback/Archive] XML documentation comments – document APIs using /// comments | Microsoft Learn
[Wayback/Archive] xml comments – XML Auto Commenting C# in Visual Studio Code – Stack Overflow (thanks [Wayback/Archive] s2Jakob and [Wayback/Archive] Pascal Berger) taught me how to enable XML Auto Commenting in C# (type /// in front of a method to expand to a full XML comment with placeholders generated from the method signature):
Q
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?
A
Starting with [Wayback/Archive] 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, }
For me, the easiest to enable this is:
- Press
Ctrl+,on Windows/Linux or on MacOSCommand+,. - If the search field does not have the focus, press
Ctrl+F(Find) on Windows/Linux or on MacOSCommand+F. - Type
Format Typewith will get you the “Format On Type” setting under “Editor”: a generic setting for the full editor. - Enable the checkbox you see below:
- Close the settings tab (press
Ctrl+Won Windows/Linux or on MacOSCommand+W). - Profit!
[Wayback/Archive] C# XML Comments in Visual Studio Code – Simple Talk highlights my concern with this very generic setting:
I confess I don’t know for sure what other formatting features are included when we enable this option but I would love to discover this. If you find this out, drop a comment on this blog.
I guess time will tell, especially when noting which characters are involved in the expansion. Those are in the commit [Wayback/Archive] Support auto doc comment generation · 333fred/omnisharp-vscode@159de98:
- localDisposables.add(vscode.languages.registerOnTypeFormattingEditProvider(documentSelector, new FormatProvider(server, languageMiddlewareFeature), '}', ';'));
+ localDisposables.add(vscode.languages.registerOnTypeFormattingEditProvider(documentSelector, new FormatProvider(server, languageMiddlewareFeature), '}', '/', '\n', ';'));
}ending curly brace/slash\nnew-line;semi-colon
The middle two are for XML documentation comments, the others already existing. Need to keep an eye on what behaviour is new when typing those.
Some more notes
There used to be another extension that exclusively did XML Comments (I think it had it’s own implementation) that is now deprecated because of the official support, see {Wayback/Archive] C# XML Documentation Comments – Visual Studio Marketplace
C# for Visual Studio Code (powered by OmniSharp)now officially supports the documentation comment from [Wayback/Archive] v1.23.8 (December 18th, 2020). You can use the official one by turning onEditor: Format On Type.This extension will be deprecated in the future. Thanks to the users who have supported me so far.
[Wayback/Archive] Release v1.23.8 · OmniSharp/omnisharp-vscode implemented this and mentions these hard to find entries:
- Add documentation comment creation to the FormatAfterKeystrokeService (PR: [Wayback/Archive] omnisharp-roslyn#2023)
- Support auto doc comment generation ([Wayback/Archive] #8, [Wayback/Archive] PR: #4261)
Only when you open the individual links, you will find just one about XML documentation:
- [Wayback/Archive] Add documentation comment creation to the FormatAfterKeystrokeService by 333fred · Pull Request #2023 · OmniSharp/omnisharp-roslyn (no mentioning of XML)
Issue
IDocumentationCommentSnippetService was recently moved down to the Features layer, which means omnisharp can now take advantage of it and generate documentation comment snippets on typing.
…
Comment
I’d like to add that the current popular solution to do this in VS Code is to use
k--kato.docommentextension.
There have been several times already that we had to deal with an issue report in OmniSharp (unresponsive etc) that turned out to be caused by this extension.- The commit with implementation monitors both the
/and\nkeystrokes and is quite straightforward to read: [Wayback/Archive] Add documentation comment creation to the FormatAfterKeystrokeService · 333fred/omnisharp-roslyn@a109f92
- The commit with implementation monitors both the
- [Wayback/Archive] Auto generate triple slash comments with parameters · Issue #8 · OmniSharp/omnisharp-vscode has parts in the issue and parts in the comments:
Issue
From @EmYeuCoGiao on December 25, 2015 3:43
I use VSCode for unity3d dev, i type /// but this not auto gennerate
Copied from original issue: [Wayback/Archive] microsoft/vscode#1644:
[Archive/Archive] Auto generate triple slash comments with parameters · Issue #1644 · microsoft/vscode
…
This issue was moved to [Wayback/Archive] OmniSharp/omnisharp-vscode#8
Comment (2016)
I need to expose a new API from Roslyn so that the same feature is not simply re-implemented inside of OmniSharp. Remember, this feature already exists in Roslyn today, and it’s a little tricky to get right. The feature is not just generating XML doc comments on ///, but also inserting /// on enter, handling indents properly, getting undo behavior to be correct, not interfering with XML doc comment completion lists, etc.
- [Wayback/Archive] Support auto doc comment generation by 333fred · Pull Request #4261 · OmniSharp/omnisharp-vscode
Issue
Adds ‘\n’ and ‘/’ to the on-type format list, enabling vscode support for the newly-added omnisharp feature of auto-generating documentation comments. Closes [Wayback/A] #8.
Comment
This is a feature to output doccoment from AST, right? My extension is completely regular expression, so it was getting harder and harder to maintain… I’ve been wanting to get the AST from the roslyn for some time. I’ll announce the removal of my extension if necessary.
Yep. It’s using the same functionality that inserts the doc comments in VS itself.
…
Out of curiosity, how do you all control the cursor when generating doc comments? We’ve made it work in VS via a custom protocol message; however, that doesn’t exist in VSCode AFAIK.
That’s the secret: we do not. It does mean that the cursor will be placed at the end of the generated comment, but I think that’s a worthwhile tradeoff to not having the generation at all.
…
No, I have
"editor.formatOnType": false,. It’s not obliviously that this feature included informatOnType, maybe better to change description in changelog at least.
So, I have to useformatOnTypeor usek--kato.docomment, isn’t it? :(…
- [Wayback/Archive] Support auto doc comment generation by 333fred · Pull Request #4261 · OmniSharp/omnisharp-vscode
Via
Got al this because of [Wayback/Archive] vscode xml documentation – Google Search.
It also got me [Wayback/Archive] XML – Visual Studio Marketplace (code --install-extension redhat.vscode-xml)
This VS Code extension provides support for creating and editing XML documents, based on the LemMinX XML Language Server.
Note: it uses a binary version of the [Wayback/Archive] LemMinX XML Language Server, so you can run it even if you do not have Java installed, but you have to allow it to run :
The lemminx-win32.exe file is part of the assets in that repository (see for instance [Wayback] lemminx-win32.zip in [Wayback/Archive] Release 0.21.0 · redhat-developer/vscode-xml). [Wayback/Archive] vscode-xml/CONTRIBUTING.md at main · redhat-developer/vscode-xml: binary-server-development describes more about it.
Twitter thread
- [Wayback/Archive] Not cool: the Visual Studio Code setting to enable automatic XML documentation expansion is under the very generic “Format On Type”. Not intuitive so it was hard to find. Thanks @hereispascal for explaining the setting in …
[Wayback/Archive] xml comments – XML Auto Commenting C# in Visual Studio Code – Stack Overflow
- …
- [Wayback/Archive] Eventually a blog post on this will follow someday (:
On one page: [Wayback/Archive] Thread by @jpluimers on Thread Reader App
--jeroen






Leave a comment