Skip to content

IncludeExcludeFilter

Actionbot edited this page May 8, 2026 · 2 revisions

πŸ“™ Description

Apply rules to all C# [*.cs] files except selected ones (e.g., [{TestClass1.cs,TestClass2.cs}]).

πŸ’» Usage

.editorconfig-main

# StyleCop.Analyzers rules
^biak^ include [*.cs]
^biak^ exclude [{TestFile1.cs,TestFile2.cs}]

dotnet_diagnostic.SA1025.severity = error
dotnet_diagnostic.SA1026.severity = error
dotnet_diagnostic.SA1028.severity = error

^biak^ END include/exclude

# Code analysis (CAxxxx) rules
^biak^ include [*.cs]
^biak^ exclude [{TestFile1.cs,TestFile2.cs}]

dotnet_diagnostic.CA1724.severity = error
dotnet_diagnostic.CA1727.severity = error
dotnet_diagnostic.CA1716.severity = error

^biak^ END include/exclude

...

After running the Enable / Disable commands, the .editorconfig file is converted to:

# StyleCop.Analyzers rules
[*.cs]
dotnet_diagnostic.SA1025.severity = error
dotnet_diagnostic.SA1026.severity = error
dotnet_diagnostic.SA1028.severity = error

[{TestFile1.cs,TestFile2.cs}]
dotnet_diagnostic.SA1025.severity = none
dotnet_diagnostic.SA1026.severity = none
dotnet_diagnostic.SA1028.severity = none

# Code analysis (CAxxxx) rules
[*.cs]
dotnet_diagnostic.CA1724.severity = error
dotnet_diagnostic.CA1727.severity = error
dotnet_diagnostic.CA1716.severity = error

[{TestFile1.cs,TestFile2.cs}]
dotnet_diagnostic.CA1724.severity = none
dotnet_diagnostic.CA1727.severity = none
dotnet_diagnostic.CA1716.severity = none

...

As you can see, the rules are applied to all files except the specifically excluded ones.

It is also recommended to use the variable functionality together with this feature to avoid duplicating paths.

Warning

Include / Exclude filter works unstable for dotnet format command, so it is recommended to use --exlude filter, for example dotnet format --exlude TestFile1.cs TestFile2.cs

❔ Why

  • It is currently not possible to exclude multiple files using built-in syntax. Only [!name] (for a single file) or {s1,s2,s3} (without !) are supported.

  • If done manually, you would need to duplicate rules, which can lead to bugs and maintenance issues.

πŸ”— Links

βš™οΈ Enable / Disable .editorconfig rules

πŸ—‚οΈ Imports

πŸ“¦ Variables

πŸ”Ž Include / Exclude filter

πŸ§‘β€πŸ’» Find activity

βš”οΈ Find conflicts

Clone this wiki locally