diff --git a/UnitTests/UnitTests.SourceGenerators/Test_SourceGeneratorsDiagnostics.cs b/UnitTests/UnitTests.SourceGenerators/Test_SourceGeneratorsDiagnostics.cs index 1df3ac3ab44..36bdb455eb7 100644 --- a/UnitTests/UnitTests.SourceGenerators/Test_SourceGeneratorsDiagnostics.cs +++ b/UnitTests/UnitTests.SourceGenerators/Test_SourceGeneratorsDiagnostics.cs @@ -9,6 +9,7 @@ using System.Linq; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; +using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.SourceGenerators; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -249,6 +250,7 @@ public partial class SampleViewModel private void VerifyGeneratedDiagnostics(string source, params string[] diagnosticsIds) where TGenerator : class, ISourceGenerator, new() { + Type observableObjectType = typeof(ObservableObject); Type validationAttributeType = typeof(ValidationAttribute); SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(source); @@ -271,6 +273,7 @@ from assembly in AppDomain.CurrentDomain.GetAssemblies() Assert.IsTrue(resultingIds.SetEquals(diagnosticsIds)); + GC.KeepAlive(observableObjectType); GC.KeepAlive(validationAttributeType); } } diff --git a/UnitTests/UnitTests.SourceGenerators/UnitTests.SourceGenerators.csproj b/UnitTests/UnitTests.SourceGenerators/UnitTests.SourceGenerators.csproj index 6fe4ab2d352..81fd8f291e2 100644 --- a/UnitTests/UnitTests.SourceGenerators/UnitTests.SourceGenerators.csproj +++ b/UnitTests/UnitTests.SourceGenerators/UnitTests.SourceGenerators.csproj @@ -15,6 +15,7 @@ + diff --git a/build/build.cake b/build/build.cake index 585ad201e90..f4f8558189a 100644 --- a/build/build.cake +++ b/build/build.cake @@ -270,6 +270,18 @@ Task("Test") ArgumentCustomization = arg => arg.Append($"-s {baseDir}/.runsettings /p:Platform=AnyCPU"), }; DotNetCoreTest(file.FullPath, testSettings); +}).DoesForEach(GetFiles(baseDir + "/**/UnitTests.SourceGenerators.csproj"), (file) => +{ + Information("\nRunning NetCore Source Generator Unit Tests"); + var testSettings = new DotNetCoreTestSettings + { + Configuration = configuration, + NoBuild = true, + Loggers = new[] { "trx;LogFilePrefix=VsTestResults" }, + Verbosity = DotNetCoreVerbosity.Normal, + ArgumentCustomization = arg => arg.Append($"-s {baseDir}/.runsettings /p:Platform=AnyCPU"), + }; + DotNetCoreTest(file.FullPath, testSettings); }).DeferOnError(); Task("UITest")