From 417a3d31cf92ba8360c28ae28abffb37de1ea268 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Amaury=20Lev=C3=A9?= <amauryleve@microsoft.com>
Date: Mon, 22 Jun 2026 14:00:13 +0200
Subject: [PATCH 1/2] Fix double registration in
 MSTest.AotReflection.SourceGeneration PoC 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>
---
 ...Test.AotReflection.SourceGeneration.csproj | 32 +++++++++----------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/src/Analyzers/MSTest.AotReflection.SourceGeneration/MSTest.AotReflection.SourceGeneration.csproj b/src/Analyzers/MSTest.AotReflection.SourceGeneration/MSTest.AotReflection.SourceGeneration.csproj
index 4f231889e8..f3bbd6a791 100644
--- a/src/Analyzers/MSTest.AotReflection.SourceGeneration/MSTest.AotReflection.SourceGeneration.csproj
+++ b/src/Analyzers/MSTest.AotReflection.SourceGeneration/MSTest.AotReflection.SourceGeneration.csproj
@@ -8,20 +8,22 @@
     <NoWarn>$(NoWarn);NU5128</NoWarn>
     <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
     <RootNamespace>MSTest.AotReflection.SourceGeneration</RootNamespace>
-    <IsPackable>false</IsPackable>
-    <!-- PoC project — not shipped, not signed. -->
+    <!-- PoC project — packable for local experimentation but not shipped, not signed. -->
+    <IsPackable>true</IsPackable>
     <IsShipping>false</IsShipping>
     <SignAssembly>false</SignAssembly>
   </PropertyGroup>
 
+  <!-- NuGet properties -->
   <PropertyGroup>
-    <Description>
-      PoC source generator that emits the metadata MSTest's IReflectionOperations would normally
-      produce via runtime reflection (attributes, declared members, instance factories, method
-      invokers). The eventual goal is to wire this output into the MSTest adapter so it can run
-      tests under NativeAOT without performing any runtime reflection. Tracked by
-      https://github.com/microsoft/testfx/issues/1837.
-    </Description>
+    <PackageDescription>
+      <![CDATA[PoC source generator that emits the metadata MSTest's IReflectionOperations would normally
+produce via runtime reflection (attributes, declared members, instance factories, method invokers).
+The eventual goal is to wire this output into the MSTest adapter so it can run tests under NativeAOT
+without performing any runtime reflection. Tracked by https://github.com/microsoft/testfx/issues/1837.
+
+This package is experimental and non-shipping; do not take a dependency on it in production code.]]>
+    </PackageDescription>
   </PropertyGroup>
 
   <ItemGroup>
@@ -43,15 +45,11 @@
     <Compile Include="..\Shared\SymbolAccessibilityHelper.cs" Link="Shared\SymbolAccessibilityHelper.cs" />
     <Compile Include="..\MSTest.SourceGeneration\Helpers\Constants.cs" Link="Helpers\Constants.cs" />
     <Compile Include="..\MSTest.SourceGeneration\Helpers\IndentedStringBuilder.cs" Link="Helpers\IndentedStringBuilder.cs" />
+  </ItemGroup>
 
-    <!-- Share the shipping generator's proven runtime-wiring source (ModuleInitializer + Register +
-         DynamicDependency rooting) so a project that references ONLY this AOT package is fully
-         functional today, on top of the reflection-free registry this generator also emits. This is
-         intentionally shared source (not a fork) so the wiring cannot drift from MSTest.SourceGeneration
-         until the reflection-free execution path is wired up and the two generators are consolidated. -->
-    <Compile Include="..\MSTest.SourceGeneration\Generators\ReflectionMetadataGenerator.cs" Link="Generators\ReflectionMetadataGenerator.cs" />
-    <Compile Include="..\MSTest.SourceGeneration\Emitters\ReflectionMetadataEmitter.cs" Link="Emitters\ReflectionMetadataEmitter.cs" />
-    <Compile Include="..\MSTest.SourceGeneration\Models\TestAssemblyMetadata.cs" Link="Models\TestAssemblyMetadata.cs" />
+  <ItemGroup>
+    <!-- Package the generator in the analyzer directory of the nuget package -->
+    <None Include="$(OutputPath)\netstandard2.0\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
   </ItemGroup>
 
 </Project>

From 2cfbeee929f9e79cb8c0db750c3b6604960611c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Amaury=20Lev=C3=A9?= <amauryleve@microsoft.com>
Date: Mon, 22 Jun 2026 14:08:10 +0200
Subject: [PATCH 2/2] Address PR review: capitalize NuGet in pack comment

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 .../MSTest.AotReflection.SourceGeneration.csproj                | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Analyzers/MSTest.AotReflection.SourceGeneration/MSTest.AotReflection.SourceGeneration.csproj b/src/Analyzers/MSTest.AotReflection.SourceGeneration/MSTest.AotReflection.SourceGeneration.csproj
index f3bbd6a791..ff807a24cf 100644
--- a/src/Analyzers/MSTest.AotReflection.SourceGeneration/MSTest.AotReflection.SourceGeneration.csproj
+++ b/src/Analyzers/MSTest.AotReflection.SourceGeneration/MSTest.AotReflection.SourceGeneration.csproj
@@ -48,7 +48,7 @@ This package is experimental and non-shipping; do not take a dependency on it in
   </ItemGroup>
 
   <ItemGroup>
-    <!-- Package the generator in the analyzer directory of the nuget package -->
+    <!-- Package the generator in the analyzer directory of the NuGet package -->
     <None Include="$(OutputPath)\netstandard2.0\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
   </ItemGroup>
 
