Skip to content

Conversation

@Sergio0694
Copy link
Member

@Sergio0694 Sergio0694 commented Feb 9, 2026

Title. This makes it more consistent with 'cswinrtgen' and moves all output messages to the top level Run method.

I also reworked the messages to be clearer and to better match the actual work:

  • "Processing N .winmd references"
  • "Generating merged projection code"
  • "Compiling merged projection"
  • "Projection code generated -> ..."
image

Split the projection generator into distinct processing, generation and emit phases and introduce a processing state object to pass data between them.

Key changes:
- Add ProjectionGeneratorProcessingState to hold sources folder, response file path and non-projection references.
- Extract reference processing into ProcessReferences which generates the .rsp and returns the processing state.
- Move CsWinRT invocation into GenerateSources which now takes the processing state and runs the tool, throwing on non-zero exit.
- Change Emit to accept the processing state, read generated .cs files from the sources folder, build the Roslyn compilation and emit the projection DLL.
- Remove duplicated helper methods (CreateCompilationForProjection and RunCsWinRT) and inline logic; update logging and error contexts.
- Minor cleanup of usings and improved cancellation/error handling across the pipeline.

This refactor clarifies responsibilities of each phase and makes the flow more explicit and testable.
Copy link

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

Refactors the WinRT projection generator pipeline into clearer phases (processing → source generation → emit) and centralizes user-facing status messages in ProjectionGenerator.Run, aligning behavior more closely with cswinrtgen.

Changes:

  • Introduces ProjectionGeneratorProcessingState to carry state between phases.
  • Splits reference processing (ProcessReferences), CsWinRT execution (GenerateSources), and Roslyn emit (Emit) into separate steps orchestrated by Run.
  • Updates progress/status messages and phase names used for error wrapping.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/WinRT.Projection.Generator/Generation/ProjectionGeneratorProcessingState.cs Adds a small state container for cross-phase data (sources folder, rsp path, filtered references).
src/WinRT.Projection.Generator/Generation/ProjectionGenerator.cs Refactors Run into explicit phases with updated top-level logging and error-phase labels.
src/WinRT.Projection.Generator/Generation/ProjectionGenerator.Generate.cs Splits reference processing from running CsWinRT; rehomes CsWinRT process launch logic.
src/WinRT.Projection.Generator/Generation/ProjectionGenerator.Emit.cs Updates emit logic to consume state from the processing phase and emits the final DLL.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Make the projection generator responsive to cancellation by calling args.Token.ThrowIfCancellationRequested at key points: inside the source file processing loop, after loading metadata references, after compilation creation, and before emit. This prevents long-running emit work from continuing when the operation has been cancelled.
Append the .dll extension to the generated projection assembly path in the console log to make the logged filename explicit. This is a logging-only change to improve clarity; no functional behavior is altered.
Improve clarity and resource handling in the projection generator: reword XML doc comments to better describe processing and emit phases; parse sources into syntax trees (comment fix) and adjust comment wording for building references; emit compilation using an explicit using block and a separate EmitResult variable to ensure proper disposal; reformat GenerateRspFile signature and clarify its parameter docs; initialize PathAssemblyResolver in the rsp generation loop; add inline comments marking processing, generation and compilation phases. These are primarily readability and resource-management improvements without changing core logic.
Add explicit error handling and well-known exceptions for cswinrt.exe failures.

- New exceptions in WellKnownProjectionGeneratorExceptions: CsWinRTProcessStartError (with/without inner exception) and CsWinRTProcessError (includes exit code).
- Update ProjectionGenerator.Generate to safely start the cswinrt process, detect a null Process return, wrap start failures (excluding existing well-known exceptions), read StandardError, wait for exit, and throw the new well-known exceptions when the process fails to start or exits with a non-zero code.
- Add required using and pragma to accommodate the changes.

These changes improve diagnostics and robustness when invoking the external cswinrt.exe tool.
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.

1 participant