Uh oh!
There was an error while loading. Please reload this page.
Fix double registration in MSTest.AotReflection.SourceGeneration PoC and make it packable (non-shipping) - #9338
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>
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
c6839b9
into
microsoft:mainUh oh!
There was an error while loading. Please reload this page.
…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>
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.