Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Oct 29, 2025

Closes #28290

  1. Remove [EventSourceAutoGenerate], we rely on just [EventSource] + no explicit ctors
  2. Introduce a new global SourceGenerators - EventSourceGenerator (and move the existing impl from SPC.Generators to this new project)
  3. Update slnx files (via the UpdateSolutionFiles task)
  4. Migrate all classes with [EventSource] to use the SG. Except for the ones with EventSourceSettings.EtwSelfDescribingEventFormat -- there are 3 ES impl defining this settings 🤔

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 29, 2025
@EgorBo EgorBo changed the title Es cleanup Introduce a new internal EventSourceGenerator and use it for all ES implementations Oct 29, 2025
@EgorBo
Copy link
Member Author

EgorBo commented Oct 29, 2025

hm.. probably should move the SLNX update to a separate (last) commit (or maybe even PR?)

…+ no explicit ctors

2) Introduce a new global SourceGenerators - EventSourceGenerator (and move the existing impl from SPC.Generators to this new project)
3) Update slnx files (via the UpdateSolutionFiles task)
4) Migrate all classes with [EventSource] to use the SG. Except for the ones with EtwSelfDescribingEventFormat
@stephentoub
Copy link
Member

we rely on just [EventSource] + no explicit ctors

We will likely want more than just this, e.g. it'll need to be partial.

@stephentoub
Copy link
Member

Update slnx files

Do we need to modify the slnx files? Could we instead globally include via .props?

@EgorBo
Copy link
Member Author

EgorBo commented Oct 29, 2025

Update slnx files

Do we need to modify the slnx files? Could we instead globally include via .props?

it's not needed to build the projects, but needed for people opening slnx files for the SG project to show up there in slnx. All other source generator projects are already added there (added automatically by the UpdateSolutionFile task, which is manually invoked (it's slow))

@EgorBo EgorBo marked this pull request as ready for review November 4, 2025 22:45
Copilot AI review requested due to automatic review settings November 4, 2025 22:45
Copy link
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 introduces a source generator for EventSource classes to automatically generate constructors and metadata, eliminating the need for manual boilerplate code. The generator creates parameterless constructors that call the base EventSource constructor with the correct parameter order (name, guid).

Key changes:

  • Introduces EventSourceGenerator source generator that triggers on classes with [EventSource] attribute
  • Removes [EventSourceAutoGenerate] attribute and makes affected EventSource classes partial
  • Changes EventSource base constructor parameter order from (Guid, string) to (string, Guid) for consistency
  • Removes manual constructors from EventSource classes across the codebase

Reviewed Changes

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

Show a summary per file
File Description
EventSourceGenerator.cs New source generator that creates constructors for EventSource classes
EventSourceGenerator.Parser.cs Parser logic to extract EventSource metadata and validate constructors
EventSourceGenerator.Emitter.cs Code generation logic for constructors and provider metadata
EventSource.cs Changes constructor parameter order and visibility for source generator
TraceLoggingEventSource.cs Updates constructor call to match new parameter order
Multiple EventSource classes Removes manual constructors and adds partial keyword
NetCoreAppLibrary.props Registers EventSourceGenerator
generators.targets Enables generator for source projects
Directory.Build.props Suppresses ESGEN001 warnings globally
Comments suppressed due to low confidence (1)

src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Parser.cs:24

  • The parser only checks for NamespaceDeclarationSyntax but doesn't check for FileScopedNamespaceDeclarationSyntax. This will cause the generator to skip classes in file-scoped namespaces. Use BaseNamespaceDeclarationSyntax as the base type to handle both traditional and file-scoped namespace declarations.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Unused?

@EgorBo
Copy link
Member Author

EgorBo commented Nov 11, 2025

@copilot address the recent feedback

@EgorBo
Copy link
Member Author

EgorBo commented Nov 11, 2025

oh, that doesn't work that way?

@jkotas
Copy link
Member

jkotas commented Nov 11, 2025

oh, that doesn't work that way?

You can ask it to create a PR against your branch, but it will never do a direct push into your branch currently.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thank you!

@jkotas jkotas merged commit d3504b6 into dotnet:main Nov 16, 2025
164 checks passed
EgorBo added a commit that referenced this pull request Nov 17, 2025
This is the result of `dotnet build /t:UpdateSolutionFile slngen.proj`
command (except for SPC.slnx which is not covered by the script so I
added it there by hands).

It's not build related, just for the people who open slnx for
development, so the newly added SG
(#121180) can show up in the
solution tree.

<img width="1092" height="529"
alt="{3B42DE0C-82BD-4E62-8AEC-11221AE39139}"
src="https://github.com/user-attachments/assets/a13b4d19-b12b-48ec-8a0b-7b7743b4ac12"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add EventSource guid ctors for non-reflection creation

6 participants