diff --git a/MSTest.slnf b/MSTest.slnf
index 3c3f4c624a..f8858c6031 100644
--- a/MSTest.slnf
+++ b/MSTest.slnf
@@ -11,6 +11,7 @@
"src\\Analyzers\\MSTest.Analyzers.CodeFixes\\MSTest.Analyzers.CodeFixes.csproj",
"src\\Analyzers\\MSTest.Analyzers.Package\\MSTest.Analyzers.Package.csproj",
"src\\Analyzers\\MSTest.Analyzers\\MSTest.Analyzers.csproj",
+ "src\\Analyzers\\MSTest.AotReflection.SourceGeneration\\MSTest.AotReflection.SourceGeneration.csproj",
"src\\Analyzers\\MSTest.GlobalConfigsGenerator\\MSTest.GlobalConfigsGenerator.csproj",
"src\\Analyzers\\MSTest.SourceGeneration\\MSTest.SourceGeneration.csproj",
"src\\Package\\MSTest.Sdk\\MSTest.Sdk.csproj",
diff --git a/TestFx.slnx b/TestFx.slnx
index 991e9dc8db..4f9fc147da 100644
--- a/TestFx.slnx
+++ b/TestFx.slnx
@@ -69,6 +69,7 @@
+
@@ -133,6 +134,7 @@
+
diff --git a/src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/MSTestReflectionMetadataGenerator.cs b/src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/MSTestReflectionMetadataGenerator.cs
index b94f9bc9ca..c0baa4025b 100644
--- a/src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/MSTestReflectionMetadataGenerator.cs
+++ b/src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/MSTestReflectionMetadataGenerator.cs
@@ -45,14 +45,27 @@ node is TypeDeclarationSyntax type
.Where(static model => model is not null)
.Select(static (model, _) => model!);
- IncrementalValueProvider<(string? AssemblyName, ImmutableArray Classes)> combined =
+ // Pull assembly-level attributes from the compilation (one value per run) and
+ // wrap them in an equatable model so this branch of the pipeline can stay cached
+ // when only test-class code changes.
+ IncrementalValueProvider assemblyMetadata =
+ context.CompilationProvider.Select(static (c, ct) =>
+ {
+ ct.ThrowIfCancellationRequested();
+ return new AssemblyMetadataModel(
+ TestClassModelBuilder.BuildAttributes(c.Assembly.GetAttributes()));
+ });
+
+ IncrementalValueProvider<(string? AssemblyName, AssemblyMetadataModel Metadata, ImmutableArray Classes)> combined =
context.CompilationProvider.Select(static (c, _) => c.AssemblyName)
- .Combine(testClasses.Collect());
+ .Combine(assemblyMetadata)
+ .Combine(testClasses.Collect())
+ .Select(static (tuple, _) => (tuple.Left.Left, tuple.Left.Right, tuple.Right));
context.RegisterImplementationSourceOutput(combined, static (ctx, payload) =>
{
string assemblyName = payload.AssemblyName ?? "Unknown";
- string source = MetadataRegistryEmitter.EmitRegistry(assemblyName, payload.Classes);
+ string source = MetadataRegistryEmitter.EmitRegistry(assemblyName, payload.Metadata, payload.Classes);
ctx.AddSource("MSTestReflectionMetadata.Registry.g.cs", SourceText.From(source, Encoding.UTF8));
});
}
diff --git a/src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/MetadataRegistryEmitter.cs b/src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/MetadataRegistryEmitter.cs
index 7582344e7d..efead40f59 100644
--- a/src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/MetadataRegistryEmitter.cs
+++ b/src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/MetadataRegistryEmitter.cs
@@ -32,6 +32,7 @@ public static string EmitSupportTypes()
sb.AppendLine("using System;");
sb.AppendLine("using System.Collections.Generic;");
+ sb.AppendLine("using System.Threading.Tasks;");
sb.AppendLine();
using (sb.Block($"namespace {GeneratedNamespace}"))
@@ -57,8 +58,10 @@ public static string EmitSupportTypes()
sb.AppendLine("public Type[] ParameterTypes { get; init; } = Array.Empty();");
sb.AppendLine("public string[] ParameterNames { get; init; } = Array.Empty();");
sb.AppendLine("public Attribute[] Attributes { get; init; } = Array.Empty();");
- sb.AppendLine("/// Direct invoker — replaces .");
- sb.AppendLine("public Func