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.
--exclude-output
Section titled “--exclude-output”Use this to keep something out of the build set while leaving the analysis intact: benchmarks, samples, a project your pipeline handles separately.
dotnet affected --dry-run --verbose --exclude-output '\.Benchmarks\.csproj$'1 files have changed referenced by 1 projects0 NuGet Packages have changed7 projects are affected by these changes1 projects were excludedChanged ProjectsName PathDotnetAffected.Abstractions /repo/src/DotnetAffected.Abstractions/DotnetAffected.Abstractions.csproj
Affected ProjectsName Pathdotnet-affected /repo/src/dotnet-affected/dotnet-affected.csprojdotnet-affected.Tests /repo/test/dotnet-affected.Tests/dotnet-affected.Tests.csproj...
Excluded ProjectsName Pathdotnet-affected.Benchmarks /repo/benchmarks/dotnet-affected.Benchmarks/dotnet-affected.Benchmarks.csprojBecause the project is still evaluated, changes flow through it: excluding a mid-chain library keeps everything depending on that library in the results.
--exclude-discovery
Section titled “--exclude-discovery”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.
dotnet affected --verbose --exclude-discovery '/legacy/'1 files have changed referenced by 1 projects0 NuGet Packages have changed7 projects are affected by these changes0 projects were excluded1 projects were excluded from discovery...
Projects Excluded from DiscoveryPath/repo/benchmarks/dotnet-affected.Benchmarks/dotnet-affected.Benchmarks.csprojThe 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.
Writing the pattern
Section titled “Writing the pattern”- The pattern is matched with
Regex.IsMatchagainst 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 containingTestswith any character on either side; to match a literal dot, escape it:'\.Tests\.'.- Matching is case-sensitive unless you say otherwise:
'(?i)tests'.
# Everything under a directorydotnet affected --exclude-output '/samples/'
# Test projects by file namedotnet affected --exclude-output '\.Tests\.csproj$'
# Two things at oncedotnet affected --exclude-output '(/samples/|\.Benchmarks\.csproj$)'--exclude is obsolete
Section titled “--exclude is obsolete”-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.