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.
Generate the project
Section titled “Generate the project”dotnet affected --verbose1 files have changed referenced by 1 projects0 NuGet Packages have changed5 projects are affected by these changes0 projects were excluded...WRITE: /repo/affected.projThe file is written to the repository path as affected.proj. Both the name and the directory are configurable with
--output-name and --output-dir.
Build and test it
Section titled “Build and test it”dotnet build affected.projdotnet test affected.projRestore works the same way:
dotnet restore affected.projSkip the work when nothing changed
Section titled “Skip the work when nothing changed”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:
dotnet affectedif [ "$?" -eq 0 ]; then dotnet build affected.projfiSee Exit codes for the full contract.
Preview without writing files
Section titled “Preview without writing files”--dry-run prints the file that would be written, contents included:
dotnet affected --dry-runDRY-RUN: WRITE /repo/affected.projDRY-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>