Building only changed projects in a .NET monorepo with dotnet-affected
Sander ten Brinke describes a client's .NET [1]monorepo with several APIs, a web frontend, a desktop app and shared libraries, where each application's pipeline ran on any change under src/. In one week, pushes to the main branch caused 41 pipeline runs, and 36 of them built and deployed an application that had not changed. Skipping those runs would have saved about 400 of the 480 agent minutes spent that week.
The author says path filters are not enough, because shared code means a change in one folder can affect another project. The tool [2]dotnet-affected compares two commits, finds the projects that the changed files belong to, and walks the [3]MSBuild project graph to find every project that depends on them. It also takes changed .csproj files and NuGet package versions into account. The author ran it on several months of changes and it identified the affected projects correctly every time.
The pipeline gets a first stage, CheckAffected, which runs the tool and skips the build and deploy stages when the application is not affected. The pipeline always runs when someone starts it manually or when a file on the always-build list changes. The example uses Azure Pipelines, but the author believes the approach should work with other CI systems.
Repository dotnet-affected github.com
Open source CLI tool that finds which .NET projects a commit affects, via the MSBuild project graph, so CI builds only those.
Read the original stenbrinke.nlDiscussion
Sources
-
Sander ten Brinke
Build only what changed in your .NET monorepo with dotnet-affected




