Fix double registration in MSTest.AotReflection.SourceGeneration PoC and make it packable (non-shipping)#9338
Merged
Evangelink merged 2 commits intoJun 22, 2026
Conversation
…and make it packable (non-shipping) The PoC analyzer assembly compiled in MSTest.SourceGeneration's ReflectionMetadataGenerator (which is itself [Generator]), so referencing the PoC ran two source generators. Each emitted a [ModuleInitializer] calling ReflectionMetadataHook.Register for the same assembly, registering it twice with the composite provider and doubling discovered test counts (a 2-test project reported 4). The PoC's own RuntimeRegistrationEmitter already emits a complete, richer (5-arg, attribute-carrying) registration plus DynamicDependency rooting, so the shared shipping generator was redundant. Remove the three shared Compile includes (generator, emitter, model) that nothing in the PoC referenced; only one ModuleInitializer is emitted now and a sample reports the correct test count. Also make the project packable as a non-shipping package (IsPackable=true, IsShipping=false) so it can be consumed locally for experimentation; the generator dll is packed under analyzers/dotnet/cs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR fixes duplicate MSTest registration in the experimental MSTest.AotReflection.SourceGeneration generator by removing shared “shipping” generator sources, and makes the PoC packable as a non-shipping NuGet analyzer for local experimentation.
Changes:
- Remove shared
MSTest.SourceGenerationgenerator/emitters/modelsCompile Includes to prevent double[ModuleInitializer]registration. - Enable packing (
IsPackable=true,IsShipping=false) and add a pack rule to place the analyzer DLL underanalyzers/dotnet/cs. - Update package description metadata to a dedicated
PackageDescription.
Show a summary per file
| File | Description |
|---|---|
| src/Analyzers/MSTest.AotReflection.SourceGeneration/MSTest.AotReflection.SourceGeneration.csproj | Removes shared generator sources to prevent double registration; enables non-shipping packing and adds analyzer packing entry. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 3
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0101
approved these changes
Jun 22, 2026
Evangelink
enabled auto-merge (squash)
June 22, 2026 12:32
Evangelink
disabled auto-merge
June 22, 2026 12:36
Evangelink
added a commit
that referenced
this pull request
Jun 22, 2026
…ounts After the build progresses past the restore/compile fixes, verify-nupkgs.ps1 fails because MSTest.AotReflection.SourceGeneration (made packable as a non-shipping PoC in #9338) is a 4.3.0 package not present in the expected file-count table, so it is validated with an empty expected value. Add it with its actual content count (6: [Content_Types].xml, Icon.png, .nuspec, the analyzer dll, .psmdcp, .rels). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
What
Two fixes to the experimental
MSTest.AotReflection.SourceGenerationPoC:Fix double test registration. The PoC
.csproj<Compile Include>-edMSTest.SourceGeneration'sReflectionMetadataGenerator.cs— which is itself decorated with[Generator]. As a result, the PoC analyzer assembly ran two source generators, and each emitted a[ModuleInitializer]that calledReflectionMetadataHook.Register(...)for the same assembly:MSTestSourceGeneratedReflectionMetadata(shipping generator, 3-argRegister)MSTestAotSourceGeneratedReflectionMetadata(PoC generator, 5-argRegister)CompositeSourceGeneratedReflectionDataProviderappends both providers with no de-duplication, so every test class was discovered twice. A trivial 2-test project reported 4 passing tests.The PoC's own
RuntimeRegistrationEmitteralready emits a complete and strictly richer registration (5-arg overload carrying materialized type/assembly attributes) plus[DynamicDependency]rooting, so the shared shipping generator was redundant. The three sharedCompileincludes (ReflectionMetadataGenerator.cs,ReflectionMetadataEmitter.cs,TestAssemblyMetadata.cs) — none of which were referenced by any PoC source — are removed. Only one[ModuleInitializer]is emitted now.Make the project packable as a non-shipping package (
IsPackable=true,IsShipping=false) so it can be consumed locally for experimentation. The generator dll is packed underanalyzers/dotnet/cs. The package lands inartifacts/packages/<config>/NonShippingand is not published.Verification
MSTest.AotReflection.SourceGeneration.UnitTests: 66/66 pass.total: 4(each test discovered twice).total: 2, and only the PoC's generated files are emitted (the duplicateSample.MSTestReflectionMetadata.g.csfrom the shipping generator is gone).dotnet packproducesMSTest.AotReflection.SourceGeneration.<ver>.nupkginNonShipping, with the analyzer dll atanalyzers/dotnet/cs/.Notes
This remains a PoC tracked by #1837. The reflection-free registry it emits is still not consumed by the adapter (runtime discovery continues to go through
ReflectionMetadataHook+[DynamicDependency]), which is out of scope for this change.