Language rules

Code-style language rules affect how various constructs of .NET programming languages, for example, modifiers, and parentheses, are used. The rules fall into the following categories:

  • .NET style rules: Rules that apply to both C# and Visual Basic. The option names for these rules start with the prefix dotnet_style_.
  • C# style rules: Rules that are specific to C# code. The option names for these rules start with the prefix csharp_style_.
  • Visual Basic style rules: Rules that are specific to Visual Basic code. The option names for these rules start with the prefix visual_basic_style_.

Option format

Options for language rules can be specified in a configuration file with the following format:

option_name = value (Visual Studio 2019 version 16.9 and later)

or

option_name = value:severity

  • Value

    For each language rule, you specify a value that defines if or when to prefer the style. Many rules accept a value of true (prefer this style) or false (do not prefer this style). Other rules accept values such as when_on_single_line or never.

  • Severity (optional in Visual Studio 2019 version 16.9 and later versions)

    The second part of the rule specifies the severity level for the rule. When specified in this way, the severity setting is only respected inside development IDEs, such as Visual Studio. It is not respected during build.

    To enforce code style rules at build time, set the severity by using the rule ID-based severity configuration syntax for analyzers instead. The syntax takes the form dotnet_diagnostic.<rule ID>.severity = <severity>, for example, dotnet_diagnostic.IDE0040.severity = none. For more information, see severity level.

Tip

Starting in Visual Studio 2019 version 16.3, you can configure code style rules from the Quick Actions light bulb menu after a style violation occurs. For more information, see Automatically configure code styles in Visual Studio.

.NET style rules

The style rules in this section are applicable to both C# and Visual Basic.

C# style rules

The style rules in this section are applicable to C# language only.

Visual Basic style rules

The style rules in this section are applicable to Visual Basic language only.

See also