Skip to content

Fix GenerateResource to track all ResXFileRef linked files for incremental builds#13327

Merged
OvesN merged 11 commits intodotnet:mainfrom
OvesN:dev/veronikao/resgen-track-all-linked-file-dependencies
Mar 5, 2026
Merged

Fix GenerateResource to track all ResXFileRef linked files for incremental builds#13327
OvesN merged 11 commits intodotnet:mainfrom
OvesN:dev/veronikao/resgen-track-all-linked-file-dependencies

Conversation

@OvesN
Copy link
Copy Markdown
Contributor

@OvesN OvesN commented Mar 4, 2026

Fixes #13158

Context

ResGenDependencies.GetResXFileReferenceDependencies tracked linked file dependencies for incremental builds by checking resource is FileStreamResource. However, MSBuildResXReader.AddLinkedResource only produces a FileStreamResource for types that are not String, Byte[], or MemoryStream. Those three common cases were returned as StringResource / LiveObjectResource instead, meaning their linked file paths were invisible to the dependency tracker.

As a result, modifying a text file or byte-array file linked via ResXFileRef did not trigger resource regeneration on incremental build, while modifying an image (e.g., .bmp linked as System.Drawing.Bitmap) did.

Changes Made

  • New interface ILinkedFileResource : IResource with a nullable LinkedFilePath property, representing any resource that originated from a ResXFileRef entry. This interface is implemented by the following classes: LiveObjectResource, StringResource,FileStreamResource
  • ResGenDependencies checks resource is ILinkedFileResource linked && linked.LinkedFilePath is not null instead of resource is FileStreamResource, so all ResXFileRef types are tracked.

Testing

  • Added InlineStringIsNotLinkedFileResource — verifies inline string resources have LinkedFilePath == null.
  • Added FileRefStringIsLinkedFileResource — verifies string file refs have non-null LinkedFilePath.
  • Added LinkedFilesTrackedForAllResourceTypes — verifies that GetResXFileInfo with useMSBuildResXReader: true tracks linked files for all resource types (System.String, System.Byte[], System.IO.MemoryStream, and System.Drawing.Bitmap), not just FileStreamResource.
  • -Added ForceOutOfDateLinkedTextFile — regression test that exercises the full GenerateResource task: creates a resx with a linked text file (System.String), runs the task, touches the text file, runs again, and asserts the .resources output was regenerated (this scenario previously failed because text-linked files weren't tracked).
  • Manual end-to-end verification: built a project with linked text and image resources, modified the text file, confirmed incremental build regenerates the .resources file (previously skipped).

Copilot AI review requested due to automatic review settings March 4, 2026 14:45
@OvesN OvesN self-assigned this Mar 4, 2026
@OvesN OvesN changed the title Dev/veronikao/resgen track all linked file dependencies Fix GenerateResource to track all ResXFileRef linked files for incremental builds Mar 4, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ILinkedFileResource with LinkedFilePath to represent resources that may carry a linked file dependency.
  • Plumbs linkedFilePath through StringResource/LiveObjectResource creation paths for ResXFileRef entries.
  • Updates ResGenDependencies to detect linked inputs via ILinkedFileResource instead of FileStreamResource only, and adds unit tests for the new linked-path behavior in MSBuildResXReader.

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.

OvesN and others added 3 commits March 4, 2026 15:57
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
@OvesN OvesN requested review from AR-May and JanProvaznik March 4, 2026 15:31
Copy link
Copy Markdown
Member

@AR-May AR-May left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Member

@JanProvaznik JanProvaznik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a question about semantics of null but otherwise a good change

@OvesN OvesN enabled auto-merge (squash) March 5, 2026 14:32
@OvesN OvesN disabled auto-merge March 5, 2026 15:02
@OvesN OvesN merged commit 9d58c2f into dotnet:main Mar 5, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GenerateResource Task for EmbeddedResource with Linked Files Does not Detect Changes for Text Files

5 participants