Skip to content
v7 is in preview. Install it with dotnet tool install dotnet-affected --prerelease, and see what changed since v6.

Excluding projects

There are two exclusion options, and they differ in kind rather than degree.

Option The project is… Its dependents…
--exclude-output discovered and evaluated, but left out of the results are still found through it
--exclude-discovery dropped before the graph is built, so it is not a starting point are unaffected — unless they reference it

Both take a .NET regular expression matched against each project’s full path.

Use this to keep something out of the build set while leaving the analysis intact: benchmarks, samples, a project your pipeline handles separately.

Terminal window
dotnet affected --dry-run --verbose --exclude-output '\.Benchmarks\.csproj$'
1 files have changed referenced by 1 projects
0 NuGet Packages have changed
7 projects are affected by these changes
1 projects were excluded
Changed Projects
Name Path
DotnetAffected.Abstractions /repo/src/DotnetAffected.Abstractions/DotnetAffected.Abstractions.csproj
Affected Projects
Name Path
dotnet-affected /repo/src/dotnet-affected/dotnet-affected.csproj
dotnet-affected.Tests /repo/test/dotnet-affected.Tests/dotnet-affected.Tests.csproj
...
Excluded Projects
Name Path
dotnet-affected.Benchmarks /repo/benchmarks/dotnet-affected.Benchmarks/dotnet-affected.Benchmarks.csproj

Because the project is still evaluated, changes flow through it: excluding a mid-chain library keeps everything depending on that library in the results.

Use this when a project cannot be loaded at all — a project MSBuild fails to evaluate would otherwise take the whole run down while the graph is being built.

Terminal window
dotnet affected --verbose --exclude-discovery '/legacy/'
1 files have changed referenced by 1 projects
0 NuGet Packages have changed
7 projects are affected by these changes
0 projects were excluded
1 projects were excluded from discovery
...
Projects Excluded from Discovery
Path
/repo/benchmarks/dotnet-affected.Benchmarks/dotnet-affected.Benchmarks.csproj

The two lists are reported separately, and the discovery line only appears when something was actually excluded that way. Excluded-from-discovery projects are listed by path alone: nothing evaluated them at discovery time, so there is no project name to show.

  • The pattern is matched with Regex.IsMatch against the project’s absolute path, so it matches anywhere in the path — it is not anchored, and it is not a glob.
  • . is a regex wildcard. .Tests. matches any path containing Tests with any character on either side; to match a literal dot, escape it: '\.Tests\.'.
  • Matching is case-sensitive unless you say otherwise: '(?i)tests'.
Terminal window
# Everything under a directory
dotnet affected --exclude-output '/samples/'
# Test projects by file name
dotnet affected --exclude-output '\.Tests\.csproj$'
# Two things at once
dotnet affected --exclude-output '(/samples/|\.Benchmarks\.csproj$)'

-e/--exclude still works and behaves exactly like --exclude-output, which it is now an alias for. When both are given, --exclude-output wins.

Exclusion and the “nothing changed” exit code

Section titled “Exclusion and the “nothing changed” exit code”

Exclusion happens before the result is judged empty, so excluding everything that changed produces exit code 166 — the same as if nothing had changed at all. See Exit codes.