Skip to content

Make projection generation incremental across reference assembly changes - #2652

Open
Sergio Pedri (Sergio0694) wants to merge 8 commits into
staging/3.0from
sergio0694-projection-incremental-inputs
Open

Sergio Pedri (Sergio0694) wants to merge 8 commits into
staging/3.0from
sergio0694-projection-incremental-inputs

Conversation

@Sergio0694

Copy link
Copy Markdown
Member

Summary

Make the projection generation targets incremental when an unrelated project reference's reference assembly changes, and keep the generated projection .dll-s byte-stable so the interop generator cache keeps hitting.

Motivation

Whenever the reference assembly of any project reference of an app changed, the SDK, SDK XAML, merged and component projection generators re-ran, even though nothing they consume had changed. The regenerated .dll-s were also not byte-identical to the previous ones: Roslyn records every compilation reference (name and MVID) in the embedded PDB, so an unrelated reference changing its MVID changed the output. The interop generator fingerprints those .dll-s by whole-file hash, so its cache then missed too (Generating interop code instead of Cached interop code). On a large app (the Microsoft Store client, 62 projects) this cost roughly 50 seconds per incremental build.

Changes

  • src/WinRT.Projection.Generator/: select the Roslyn compilation references by projection mode (new ProjectionGenerator.ReferenceAssemblies.cs), so generated bytes no longer depend on unrelated references. SDK mode keeps only framework references and WinRT.Runtime (plus WinRT.Sdk.Projection for the XAML projection). Merged and component modes keep the WinRT reference assemblies, components, and their dependency closure. References are deduplicated and ordered by name then path, and embedded PDBs are preserved. The generator also writes a <AssemblyName>.references file next to each projection, listing exactly what it compiled against.
  • nuget/Microsoft.Windows.CsWinRT.CsWinRTGen.targets: narrow the Inputs of the four projection targets (renaming _CsWinRTComputeProjectionGenWinMDInputs to _CsWinRTComputeProjectionGenInputs). .winmd files are now listed as items so their timestamps count, the .references files are read into Inputs, the XAML target now tracks WinRT.Sdk.Projection.dll, and the input hash covers every reference path with its reference-projection classification and the Windows SDK metadata. The .references files are registered in FileWrites, and the precompiled SDK copy path deletes stale ones.
  • src/Tests/ProjectionWriterTest/: new Test_ProjectionReferences.cs with determinism tests (unrelated, changed and reordered references produce identical bytes, for base SDK, XAML and component modes), plus small test infrastructure changes (deterministic helper compilation, WinRT.Internal metadata path).

Validation

  • Release build with zero warnings, and 17 targeted tests passing.
  • Full Windows SDK and SDK XAML projections generated with and without unrelated references have identical SHA256s.
  • On a scratch app, after a referenced project's public API edit the SDK, XAML and merged targets skip, the component target re-runs with identical bytes, and the interop generator reports Cached interop code. A .winmd change, reference projection change, WinRT.Runtime change or component change still regenerates.

Known limitations

  • Rebuilding a referenced component still re-runs SDK, XAML and merged, because cswinrtwinmdgen writes different .winmd bytes even after an implementation-only edit (needs a WinMD generator change).
  • Unrelated file or package references still re-run the merged target, because any of them could be a reference projection (output stays identical and interop stays cached).
  • Not covered: hardening the interop fingerprint against PDB-only churn, a Native AOT publish run, and a live Windows SDK version bump.

Restrict the Roslyn compilation references of the projection generator to the ones each projection mode needs, so generated bytes no longer depend on unrelated references. Narrow the Inputs of the projection generation targets so they no longer re-run when an unrelated project reference's reference assembly changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Sergio0694
Sergio Pedri (Sergio0694) marked this pull request as ready for review November 11, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CsWinRT 3.0 performance Related to performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant