From 1f8b4682109be585ac0cc87a309ddba83767a125 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Tue, 11 Mar 2025 10:37:25 +0100 Subject: [PATCH] Add more logging to dotnet test tracing --- .../dotnet-test/SolutionAndProjectUtility.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/SolutionAndProjectUtility.cs b/src/Cli/dotnet/commands/dotnet-test/SolutionAndProjectUtility.cs index 6eeeb1db0912..5133d21f3b43 100644 --- a/src/Cli/dotnet/commands/dotnet-test/SolutionAndProjectUtility.cs +++ b/src/Cli/dotnet/commands/dotnet-test/SolutionAndProjectUtility.cs @@ -4,6 +4,8 @@ using Microsoft.Build.Evaluation; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools; +using Microsoft.DotNet.Tools.Common; +using Microsoft.DotNet.Tools.Test; using NuGet.Packaging; using LocalizableStrings = Microsoft.DotNet.Tools.Test.LocalizableStrings; @@ -112,15 +114,26 @@ public static IEnumerable GetProjectProperties(string projectFilePat // Check if TargetFramework is specified in global properties if (globalProperties.TryGetValue(ProjectProperties.TargetFramework, out string targetFramework)) { + Logger.LogTrace(() => $"Loaded project '{Path.GetFileName(projectFilePath)}' with global property TargetFramework '{targetFramework}'."); + if (IsValidTargetFramework(project, targetFramework)) { + Logger.LogTrace(() => $"Project '{Path.GetFileName(projectFilePath)}' with TargetFramework '{targetFramework}': before re-evaluation '{ProjectProperties.IsTestingPlatformApplication}' is '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}'."); + project.SetProperty(ProjectProperties.TargetFramework, targetFramework); project.ReevaluateIfNecessary(); - if (GetModuleFromProject(project) is {} module) + Logger.LogTrace(() => $"Project '{Path.GetFileName(projectFilePath)}' with TargetFramework '{targetFramework}': after re-evaluation '{ProjectProperties.IsTestingPlatformApplication}' is '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}'."); + + if (GetModuleFromProject(project) is { } module) { projects.Add(module); } } + else + { + // TODO: When can this happen? Should we explicitly error? + Logger.LogTrace(() => $"Project '{Path.GetFileName(projectFilePath)}' with TargetFramework '{targetFramework}' was considered invalid."); + } } else { @@ -128,6 +141,8 @@ public static IEnumerable GetProjectProperties(string projectFilePat if (string.IsNullOrEmpty(targetFrameworks)) { + Logger.LogTrace(() => $"Loaded project '{Path.GetFileName(projectFilePath)}' has '{ProjectProperties.IsTestingPlatformApplication}' = '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}'."); + if (GetModuleFromProject(project) is {} module) { projects.Add(module); @@ -135,11 +150,15 @@ public static IEnumerable GetProjectProperties(string projectFilePat } else { + Logger.LogTrace(() => $"Loaded project '{Path.GetFileName(projectFilePath)}' has '{ProjectProperties.IsTestingPlatformApplication}' = '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}' (TFMs: '{targetFrameworks}')."); + var frameworks = targetFrameworks.Split(CliConstants.SemiColon, StringSplitOptions.RemoveEmptyEntries); foreach (var framework in frameworks) { project.SetProperty(ProjectProperties.TargetFramework, framework); project.ReevaluateIfNecessary(); + Logger.LogTrace(() => $"Loaded project '{Path.GetFileName(projectFilePath)}' has '{ProjectProperties.IsTestingPlatformApplication}' = '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}' (TFM: '{framework}')."); + if (GetModuleFromProject(project) is {} module) { projects.Add(module);