Reputation: 168
After updating Visual Studio 2019 to version 16.7.0 a few days ago, I noticed that it started creating annoying blank lines between using
directives if the first part of the namespace is not the same.
For example:
using System;
using Alpha;
using Alpha.Foo;
using Alpha.Bar;
using Bravo;
using Bravo.Utils;
Upvotes: 5
Views: 1300
Reputation: 51905
Assuming you are talking about C# source code/files, then: Select "Options" from the "Tools" menu and, in the displayed pop-up, navigate to "Text Editor ... C# ... Advanced" and uncheck the "Separate using directive groups" check-box, as shown below:
Upvotes: 7
Reputation: 2193
There is also an option via .editorconfig which is supported since a while in Visual Studio. The benefit is that this setting is "re-usable" across IDEs and can be brought into source control.
The relevant options are:
dotnet_separate_import_directive_groups
dotnet_sort_system_directives_first
See dotnet-formatting-options for more details.
The rule IDE0055
reflects formatting issues.
Add these lines to your .editorconfig to change the behavior for C# and VisualBasic
#### .NET Coding Conventions ####
[*.{cs,vb}]
# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = false
# https://learn.microsoft.com/de-de/dotnet/fundamentals/code-analysis/style-rules/ide0055
dotnet_diagnostic.IDE0055.severity = error
I found out, that new classes with using do respect the setting. Old existing classes, will not show a warning / error when there is a space between two using blocks. You need to find and clean dirty code yourself.
Upvotes: 0