Fix GenerateResource to track all ResXFileRef linked files for incremental builds#13327
Merged
OvesN merged 11 commits intodotnet:mainfrom Mar 5, 2026
Merged
Conversation
…nikao/resgen-track-all-linked-file-dependencies
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes incremental build dependency tracking for .resx files by ensuring all ResXFileRef-based resources (including System.String, System.Byte[], and MemoryStream) expose their linked file path so changes to those linked files trigger resource regeneration (fixes #13158).
Changes:
- Introduces
ILinkedFileResourcewithLinkedFilePathto represent resources that may carry a linked file dependency. - Plumbs
linkedFilePaththroughStringResource/LiveObjectResourcecreation paths forResXFileRefentries. - Updates
ResGenDependenciesto detect linked inputs viaILinkedFileResourceinstead ofFileStreamResourceonly, and adds unit tests for the new linked-path behavior inMSBuildResXReader.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Tasks/ResourceHandling/StringResource.cs | Allows StringResource to carry an optional linked file path from ResXFileRef. |
| src/Tasks/ResourceHandling/MSBuildResXReader.cs | Sets linked file path for ResXFileRef resources that are materialized as strings/byte arrays/memory streams. |
| src/Tasks/ResourceHandling/LiveObjectResource.cs | Adds optional LinkedFilePath and implements ILinkedFileResource. |
| src/Tasks/ResourceHandling/ILinkedFileResource.cs | New interface for resources that can expose a linked file dependency path. |
| src/Tasks/ResourceHandling/FileStreamResource.cs | Implements ILinkedFileResource and renames FileName to LinkedFilePath. |
| src/Tasks/ResGenDependencies.cs | Tracks linked files via ILinkedFileResource.LinkedFilePath for MSBuildResXReader-based parsing. |
| src/Tasks.UnitTests/ResourceHandling/MSBuildResXReader_Tests.cs | Adds tests validating linked vs inline string resources set LinkedFilePath appropriately. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…' of https://github.com/OvesN/msbuild into dev/veronikao/resgen-track-all-linked-file-dependencies
JanProvaznik
reviewed
Mar 5, 2026
Member
JanProvaznik
left a comment
There was a problem hiding this comment.
a question about semantics of null but otherwise a good change
…linkedFilePath parameter
JanProvaznik
reviewed
Mar 5, 2026
JanProvaznik
approved these changes
Mar 5, 2026
baronfel
reviewed
Mar 5, 2026
…' of https://github.com/OvesN/msbuild into dev/veronikao/resgen-track-all-linked-file-dependencies
This was referenced Mar 5, 2026
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.
Fixes #13158
Context
ResGenDependencies.GetResXFileReferenceDependenciestracked linked file dependencies for incremental builds by checkingresource is FileStreamResource. However,MSBuildResXReader.AddLinkedResourceonly produces aFileStreamResourcefor types that are notString,Byte[], orMemoryStream. Those three common cases were returned asStringResource/LiveObjectResourceinstead, meaning their linked file paths were invisible to the dependency tracker.As a result, modifying a text file or byte-array file linked via
ResXFileRefdid not trigger resource regeneration on incremental build, while modifying an image (e.g.,.bmplinked asSystem.Drawing.Bitmap) did.Changes Made
ILinkedFileResource : IResourcewith a nullableLinkedFilePathproperty, representing any resource that originated from aResXFileRefentry. This interface is implemented by the following classes:LiveObjectResource,StringResource,FileStreamResourceResGenDependencieschecksresource is ILinkedFileResource linked && linked.LinkedFilePath is not nullinstead ofresource is FileStreamResource, so allResXFileReftypes are tracked.Testing
InlineStringIsNotLinkedFileResource— verifies inline string resources haveLinkedFilePath == null.FileRefStringIsLinkedFileResource— verifies string file refs have non-nullLinkedFilePath.LinkedFilesTrackedForAllResourceTypes— verifies thatGetResXFileInfowithuseMSBuildResXReader: truetracks linked files for all resource types (System.String,System.Byte[],System.IO.MemoryStream, andSystem.Drawing.Bitmap), not justFileStreamResource.ForceOutOfDateLinkedTextFile— regression test that exercises the fullGenerateResourcetask: creates a resx with a linked text file (System.String), runs the task, touches the text file, runs again, and asserts the.resourcesoutput was regenerated (this scenario previously failed because text-linked files weren't tracked)..resourcesfile (previously skipped).