NewsCrawler.org

Building only changed projects in a .NET monorepo with dotnet-affected

Building only changed projects in a .NET monorepo with dotnet-affected
A flowchart of how dotnet-affected works. A git diff produces the changed files. The changed files are mapped to changed projects, and a changed Directory.Packages.props produces changed NuGet packages. Both feed into walking the project graph to find dependents, which gives the affected projects.
Image: Reddit

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.

Stars: 433Forks: 37License: MITUpdated:

Read the original stenbrinke.nlDiscussion

Sources

Published: First seen: Читать по-русски

Open as a page