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

Build and test what changed

The default output is an MSBuild Traversal SDK project. It behaves like a solution for the dotnet CLI, so you can point any command at it.

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
...
WRITE: /repo/affected.proj

The file is written to the repository path as affected.proj. Both the name and the directory are configurable with --output-name and --output-dir.

Terminal window
dotnet build affected.proj
dotnet test affected.proj

Restore works the same way:

Terminal window
dotnet restore affected.proj

dotnet affected exits with 166 when nothing changed and nothing is affected, and no output file is written. Guard the build so it does not fail on a missing affected.proj:

Terminal window
dotnet affected
if [ "$?" -eq 0 ]; then
dotnet build affected.proj
fi

See Exit codes for the full contract.

--dry-run prints the file that would be written, contents included:

Terminal window
dotnet affected --dry-run
DRY-RUN: WRITE /repo/affected.proj
DRY-RUN: CONTENTS:
<Project Sdk="Microsoft.Build.Traversal/4.1.82">
<ItemGroup>
<ProjectReference Include="/repo/src/dotnet-affected/dotnet-affected.csproj" />
<ProjectReference Include="/repo/test/dotnet-affected.Tests/dotnet-affected.Tests.csproj" />
</ItemGroup>
</Project>