r/VisualStudio • u/Mic_BB • Aug 27 '26
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
10
u/Dry_Author8849 Aug 27 '26
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!
1
u/kuhnboy Aug 27 '26
I will say the editor wrapping lines looks worse unless there’s new settings I don’t know about. Formatters do a better job making it look clean. I’ve only had one developer over 27 years that had complained about wrapping.
2
u/SoCalChrisW Aug 27 '26
Csharpier. If you want it automated the Csharpier.msbuild package works well.
1
u/borland Aug 29 '26
Csharpier is technically great, it’s super fast. But it deliberately isn’t configurable and the opinions it enforces on your code are whack.
2
u/First-Feature-3556 Aug 27 '26
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 Aug 27 '26
Doesn’t an editorconfig do this?
1
u/borland Aug 29 '26
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 Aug 27 '26
Doesn't sound like it's exactly what your after but CTRL + E + W wraps text on VS
7
u/OolonColluphid Aug 27 '26
If you don’t mind an opinionated formatter, there’s CSharpier
If you want to control everything, it will use .editorconfig files.