Skip to content

Add more logging to dotnet test tracing #47449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -112,34 +114,51 @@ public static IEnumerable<TestModule> 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
{
string targetFrameworks = project.GetPropertyValue(ProjectProperties.TargetFrameworks);

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);
}
}
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);
Expand Down