C#idiomatic C#
dotnet-formatting-optionsfundamentals/code-analysis/style-rules

Code analysis

.NET formatting options

Learn about the code-style options for formatting .NET code.

  • page fundamentals/code-analysis/style-rules/dotnet-formatting-options
  • updated 12/20/2022
  • samples CSharp, VB

The formatting options in this article apply to both C# and Visual Basic. These are options for code-style rule IDE0055.

Using directive options

Use these options to customize how you want using directives to be sorted and grouped:

Example .editorconfig file:

ini
# .NET formatting rules
[*.{cs,vb}]
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = true

dotnet_sort_system_directives_first

Property Value Description
Option name dotnet_sort_system_directives_first
Applicable languages C# and Visual Basic
Introduced version Visual Studio 2017
Option values true Sort System.* using directives alphabetically, and place them before other using directives.
false Do not place System.* using directives before other using directives.
Default option value true

Code examples:

csharp
// dotnet_sort_system_directives_first = true
using System.Collections.Generic;
using System.Threading.Tasks;
using Octokit;

// dotnet_sort_system_directives_first = false
using System.Collections.Generic;
using Octokit;
using System.Threading.Tasks;

dotnet_separate_import_directive_groups

Property Value Description
Option name dotnet_separate_import_directive_groups
Applicable languages C# and Visual Basic
Introduced version Visual Studio 2017
Option values true Place a blank line between using directive groups.
false Do not place a blank line between using directive groups.
Default option value false

Code examples:

csharp
// dotnet_separate_import_directive_groups = true
using System.Collections.Generic;
using System.Threading.Tasks;

using Octokit;

// dotnet_separate_import_directive_groups = false
using System.Collections.Generic;
using System.Threading.Tasks;
using Octokit;

See also