Make CollectDeclaredReferences target incremental#136
Open
SergeyTeplyakov wants to merge 1 commit intodfederm:mainfrom
Open
Make CollectDeclaredReferences target incremental#136SergeyTeplyakov wants to merge 1 commit intodfederm:mainfrom
SergeyTeplyakov wants to merge 1 commit intodfederm:mainfrom
Conversation
Add Inputs/Outputs to the CollectDeclaredReferences target so MSBuild can skip it on incremental builds when project file and assets file haven't changed. Two changes were needed: 1. Target Inputs/Outputs: Use \ for the Outputs path instead of GetFullPath(), since GetFullPath() resolves relative to the process working directory rather than the project directory. 2. Touch output file on unchanged content: SaveDeclaredReferences() has a write-only-if-different optimization that prevents updating the file timestamp when content is identical. This causes MSBuild to always consider the target out of date. Now we touch the file timestamp even when content is unchanged. Tested on a 305-project build (NeMo/Hardware in Azure-Compute-Move): - Before: CollectDeclaredReferences 26.8s (305 executions, 0 skipped) - After: CollectDeclaredReferences 0s (305 skipped)
stan-sz
reviewed
Apr 14, 2026
| DependsOnTargets="ResolveAssemblyReferences;PrepareProjectReferences" | ||
| Condition="'$(EnableReferenceTrimmer)' != 'false'" | ||
| Inputs="$(MSBuildProjectFullPath);$(ProjectAssetsFile)" | ||
| Outputs="$(MSBuildProjectDirectory)\$(IntermediateOutputPath)_ReferenceTrimmer_DeclaredReferences.tsv"> |
Contributor
There was a problem hiding this comment.
Suggested change
| Outputs="$(MSBuildProjectDirectory)\$(IntermediateOutputPath)_ReferenceTrimmer_DeclaredReferences.tsv"> | |
| Outputs="$([System.IO.Path]::GetFullPath('$(IntermediateOutputPath)_ReferenceTrimmer_DeclaredReferences.tsv'))"> |
stan-sz
reviewed
Apr 14, 2026
| { | ||
| // Touch the file so that MSBuild's Inputs/Outputs incrementality check | ||
| // sees a fresh timestamp and can skip the target on subsequent builds. | ||
| File.SetLastWriteTimeUtc(filePath, DateTime.UtcNow); |
Contributor
There was a problem hiding this comment.
the whole point of the if check is not to touch the timestamp if the file is identical, so this line should be reverted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Inputs/Outputs to the CollectDeclaredReferences target so MSBuild can skip it on incremental builds when project file and assets file haven't changed.
Two changes were needed:
Target Inputs/Outputs: Use \ for the Outputs path instead of GetFullPath(), since GetFullPath() resolves relative to the process working directory rather than the project directory.
Touch output file on unchanged content: SaveDeclaredReferences() has a write-only-if-different optimization that prevents updating the file timestamp when content is identical. This causes MSBuild to always consider the target out of date. Now we touch the file timestamp even when content is unchanged.
Tested on a 305-project build (NeMo/Hardware in Azure-Compute-Move):