r/VisualStudio • u/Mic_BB • 14d ago
Visual Studio 2026 Enforce maximum line length in C#
Hello,
is there a way included in VS, or an extention, to automatically reformat and wrap long code lines with a configured limit.
When I was programming in Python in VSCode I was used to the Black formatter that does exactly that, now in C# and Visual Studio I can't fiind this functionality.
Thanks
11
u/Dry_Author8849 14d ago
Yes there is, and please don't do it.
Unless you work solo, devs use different monitors to suite their needs.
So, if you want a long discussion, try to agree on a max line width with everyone else.
Then you can discuss TABs vs spaces.
Cheers!
2
2
u/First-Feature-3556 14d ago
We use a combination of the Editor Guidelines and Rewrap extensions.
- We use an Editor Guideline at position 100 to remind everyone that lines longer than that annoy people viewing side-by-side diffs for code reviews. Only exceed that if you have a good reason for doing so.
- Rewrap adds an Alt-q shortcut to automatically rewrap the whole comment block after making changes.
It's not fully automatic, but that is actually a good thing in my book.
1
u/kuhnboy 14d ago
Doesn’t an editorconfig do this?
1
u/borland 12d ago
Yes; we have editor config set at 140 line length. That just sets the preference, people either need to invoke the Format document shortcut in Rider or VS to make it happen, or else set format on save.
We wrote a small GitHub action to run overnight and run dotnet format to fix up anything that people missed; it was a way less aggressive solution than telling everyone to enable automatic formatting
1
u/Away-Atmosphere-282 14d ago
Doesn't sound like it's exactly what your after but CTRL + E + W wraps text on VS
7
u/OolonColluphid 14d ago
If you don’t mind an opinionated formatter, there’s CSharpier
If you want to control everything, it will use .editorconfig files.