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

Quick start

Run the tool from the root of your repository. With no arguments, it compares your working tree against the current HEAD, counting everything staged, unstaged and untracked.

Terminal window
dotnet affected --verbose
1 files have changed referenced by 1 projects
0 NuGet Packages have changed
5 projects are affected by these changes
0 projects were excluded
Changed Projects
Name Path
DotnetAffected.Core /repo/src/DotnetAffected.Core/DotnetAffected.Core.csproj
Affected Projects
Name Path
dotnet-affected /repo/src/dotnet-affected/dotnet-affected.csproj
dotnet-affected.Benchmarks /repo/benchmarks/dotnet-affected.Benchmarks/dotnet-affected.Benchmarks.csproj
dotnet-affected.Tests /repo/test/dotnet-affected.Tests/dotnet-affected.Tests.csproj
DotnetAffected.Core.Tests /repo/test/DotnetAffected.Core.Tests/DotnetAffected.Core.Tests.csproj
DotnetAffected.Tasks /repo/src/DotnetAffected.Tasks/DotnetAffected.Tasks.csproj
WRITE: /repo/affected.proj

Changed projects are the projects that own at least one changed file. Affected projects are the projects that depend — directly or transitively — on something that changed. The two lists are disjoint: a project appears under changed or under affected, never both.

The generated affected.proj contains both lists, because everything that changed and everything affected by those changes needs to be built:

<Project Sdk="Microsoft.Build.Traversal/4.1.82">
<ItemGroup>
<ProjectReference Include="/repo/benchmarks/dotnet-affected.Benchmarks/dotnet-affected.Benchmarks.csproj" />
<ProjectReference Include="/repo/src/dotnet-affected/dotnet-affected.csproj" />
<ProjectReference Include="/repo/src/DotnetAffected.Core/DotnetAffected.Core.csproj" />
<ProjectReference Include="/repo/src/DotnetAffected.Tasks/DotnetAffected.Tasks.csproj" />
<ProjectReference Include="/repo/test/dotnet-affected.Tests/dotnet-affected.Tests.csproj" />
<ProjectReference Include="/repo/test/DotnetAffected.Core.Tests/DotnetAffected.Core.Tests.csproj" />
</ItemGroup>
</Project>

You can then treat it like any other project file:

Terminal window
dotnet test affected.proj

See Build and test what changed for the full workflow.

--from names the baseline — a branch, tag or commit — and --uncommitted chooses how much of the working tree counts on top of it:

Terminal window
# Everything since the branch was cut, working tree included
dotnet affected --from origin/main
# Commits only, ignoring a dirty working tree — what CI wants
dotnet affected --from origin/main --uncommitted none

See Choosing what to compare.

--dry-run prints what would be written instead of creating files, and describe prints the changed and affected projects without producing any output file at all:

Terminal window
dotnet affected --dry-run
dotnet affected describe

--assume-changes pretends a project changed, which is a quick way to explore the blast radius of a change before making it:

Terminal window
dotnet affected describe --assume-changes DotnetAffected.Core

When no project changed and nothing is affected, the tool writes no output and exits with code 166 instead of 0. Use that to skip build and test steps entirely — see Exit codes.