Skip to content

Do not add projects that used leftover outputs to the cache - #198

Open
djack42 wants to merge 3 commits into
microsoft:mainfrom
djack42:upstream-pr/leftover-outputs
Open

djack42 wants to merge 3 commits into
microsoft:mainfrom
djack42:upstream-pr/leftover-outputs

Conversation

@djack42

@djack42 djack42 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes case 1 of #192.

When a project uses files that a previous build left in its output directories without writing them again, its recorded outputs miss those files. The typical case is an incremental build: CoreCompile is up to date, so the project only reads obj\...\X.dll and copies it to bin. Measured on main with tests/TestProject (details in #192):

  • with probe and enumeration fingerprinting, the entry has the leftover files as existing probes, so it never matches a build from empty output directories;
  • without it, the entry is added with no outputs, and a hit in a fresh clone restores nothing, not even bin\...\TestProject.dll.

This change detects such files and doesn't add the node to the cache:

  • Detection: a file under the project's output directories (OutDir, IntermediateOutputPath) that the node reads but never writes, and that existed before the node started (existing probes are captured for that, only when the setting is on).
  • Effect: the node is not added to the cache. Its result is still computed and used by its dependents in this build, so ICacheClient.AddNodeAsync gets a publish flag: the outputs are still hashed to build the node result, which is not stored.
  • Reporting: the build summary shows Not Added (leftover outputs): N. Each skipped node logs the file it used at high importance, and writes it to notAdded.txt in its log directory, so the cause can be fixed. The message names the other cause we met: a write by a process whose file accesses are not reported (case 2 of Cache entries are incomplete or never match when a project uses files it was not seen writing #192).
  • Setting: MSBuildCacheSkipNodesWithLeftoverOutputs. The second commit makes it on by default, since the alternative stores entries that are incomplete or never match; false restores today's behavior. Happy to drop that commit and keep it opt-in if you prefer.

A clean build (CI from a fresh clone) has nothing left over from a previous build, but it can still read files the plugin didn't see written: without #199 and #200, this check skips WPF projects and projects with satellite assemblies on clean builds too. It matters for local builds that mix incremental builds and caching, and for writes the plugin doesn't see.

Tests: FileAccessRepositoryTests and PluginSettingsTests cover the detection and the setting. #199 handles projects outside the graph that write into a node's output directories (WPF), which this check would otherwise count as leftovers.

🤖 Generated with Claude Code

djack42 and others added 3 commits November 27, 2026 10:17
The outputs of a project are the files it writes. When a project uses files left in its output directories (OutDir, IntermediateOutputPath) by a previous build without writing them, e.g. an incremental build whose targets were up to date, its outputs miss those files, and a cache hit in another clone would not place them.
With MSBuildCacheSkipNodesWithLeftoverOutputs (default false), such projects are not added to the cache. Their result is still used by their dependents in the build, so ICacheClient.AddNodeAsync takes a publish flag: the outputs are still hashed to build the node result, which is not added.
Existing probes are captured only when the setting is on, whether or not probe and enumeration fingerprinting is enabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Caching a project built over leftover outputs stores outputs without
the files it skipped, which a cache hit elsewhere would not place: a
correctness fix, so it is on by default. Setting
MSBuildCacheSkipNodesWithLeftoverOutputs to false still caches such
projects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The build summary only counted these nodes, while each one makes its dependents miss in every
build. Log the message at high importance, write it to notAdded.txt in the node log directory,
and name the other cause: a write by a process whose file accesses are not reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant