From 60af42183e2dceee8699c972eb2698d768c7ffcd Mon Sep 17 00:00:00 2001 From: David Day Date: Sat, 14 May 2022 13:42:07 -0500 Subject: [PATCH] Add support for legacy MSTest using nuget packages --- src/MSBuild.Abstractions/MSBuildHelpers.cs | 10 ++++++++-- src/MSBuild.Conversion.Facts/MSTestFacts.cs | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/MSBuild.Abstractions/MSBuildHelpers.cs b/src/MSBuild.Abstractions/MSBuildHelpers.cs index 8146ef8c6..f19c0cb64 100644 --- a/src/MSBuild.Abstractions/MSBuildHelpers.cs +++ b/src/MSBuild.Abstractions/MSBuildHelpers.cs @@ -249,14 +249,20 @@ public static bool IsAspNetCore(IProjectRootElement projectRoot, string tfm) => /// public static bool IsNETFrameworkMSTestProject(IProjectRootElement projectRoot) { + var packages = GetOrCreatePackageReferencesItemGroup(projectRoot).Items.Select(elem => elem.Include); var references = projectRoot.ItemGroups.SelectMany(GetReferences)?.Select(elem => elem.Include.Split(',').First()); - if (references is null) + if (references is null && packages is null) { return false; } else { - return MSTestFacts.MSTestReferences.All(reference => references.Contains(reference, StringComparer.OrdinalIgnoreCase)); + var hasTestReference = false; + if(references != null) + hasTestReference = MSTestFacts.MSTestReferences.All(reference => references.Contains(reference, StringComparer.OrdinalIgnoreCase)); + if (references != null) + hasTestReference = hasTestReference || MSTestFacts.MSTestPackages.All(package => packages.Contains(package, StringComparer.OrdinalIgnoreCase)); + return hasTestReference; } } diff --git a/src/MSBuild.Conversion.Facts/MSTestFacts.cs b/src/MSBuild.Conversion.Facts/MSTestFacts.cs index 7b764ff52..212785560 100644 --- a/src/MSBuild.Conversion.Facts/MSTestFacts.cs +++ b/src/MSBuild.Conversion.Facts/MSTestFacts.cs @@ -25,6 +25,11 @@ public static class MSTestFacts "Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions" ); + public static ImmutableArray MSTestPackages = ImmutableArray.Create( + "MSTest.TestAdapter", + "MSTest.TestFramework" + ); + public const string IsCodedUITestNodeName = "IsCodedUITest"; public const string TestProjectTypeNodeName = "TestProjectType"; public const string UnitTestTestProjectType = "UnitTest";