Skip to content

Commit 059a258

Browse files
committed
Cleanup TFM handling for the new dotnet test for MTP
1 parent 1402b07 commit 059a258

File tree

1 file changed

+13
-59
lines changed

1 file changed

+13
-59
lines changed

src/Cli/dotnet/commands/dotnet-test/SolutionAndProjectUtility.cs

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -105,85 +105,39 @@ public static IEnumerable<TestModule> GetProjectProperties(string projectFilePat
105105
{
106106
var projects = new List<TestModule>();
107107

108-
var globalPropertiesWithoutTargetFramework = new Dictionary<string, string>(globalProperties);
109-
globalPropertiesWithoutTargetFramework.Remove(ProjectProperties.TargetFramework);
110108

111-
var project = projectCollection.LoadProject(projectFilePath, globalPropertiesWithoutTargetFramework, null);
109+
var project = projectCollection.LoadProject(projectFilePath, globalProperties, null);
112110

113-
// Check if TargetFramework is specified in global properties
114-
if (globalProperties.TryGetValue(ProjectProperties.TargetFramework, out string targetFramework))
115-
{
116-
Logger.LogTrace(() => $"Loaded project '{Path.GetFileName(projectFilePath)}' with global property TargetFramework '{targetFramework}'.");
117-
118-
if (IsValidTargetFramework(project, targetFramework))
119-
{
120-
Logger.LogTrace(() => $"Project '{Path.GetFileName(projectFilePath)}' with TargetFramework '{targetFramework}': before re-evaluation '{ProjectProperties.IsTestingPlatformApplication}' is '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}'.");
111+
var targetFramework = project.GetPropertyValue(ProjectProperties.TargetFramework);
112+
var targetFrameworks = project.GetPropertyValue(ProjectProperties.TargetFrameworks);
113+
Logger.LogTrace(() => $"Loaded project '{Path.GetFileName(projectFilePath)}' with TargetFramework '{targetFramework}', TargetFrameworks '{targetFrameworks}', IsTestProject '{project.GetPropertyValue(ProjectProperties.IsTestProject)}', and '{ProjectProperties.IsTestingPlatformApplication}' is '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}'.");
121114

122-
project.SetProperty(ProjectProperties.TargetFramework, targetFramework);
123-
project.ReevaluateIfNecessary();
124-
125-
Logger.LogTrace(() => $"Project '{Path.GetFileName(projectFilePath)}' with TargetFramework '{targetFramework}': after re-evaluation '{ProjectProperties.IsTestingPlatformApplication}' is '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}'.");
126-
127-
if (GetModuleFromProject(project) is { } module)
128-
{
129-
projects.Add(module);
130-
}
131-
}
132-
else
115+
if (!string.IsNullOrEmpty(targetFramework) || string.IsNullOrEmpty(targetFrameworks))
116+
{
117+
if (GetModuleFromProject(project) is { } module)
133118
{
134-
// TODO: When can this happen? Should we explicitly error?
135-
Logger.LogTrace(() => $"Project '{Path.GetFileName(projectFilePath)}' with TargetFramework '{targetFramework}' was considered invalid.");
119+
projects.Add(module);
136120
}
137121
}
138122
else
139123
{
140-
string targetFrameworks = project.GetPropertyValue(ProjectProperties.TargetFrameworks);
141-
142-
if (string.IsNullOrEmpty(targetFrameworks))
124+
var frameworks = targetFrameworks.Split(CliConstants.SemiColon, StringSplitOptions.RemoveEmptyEntries);
125+
foreach (var framework in frameworks)
143126
{
144-
Logger.LogTrace(() => $"Loaded project '{Path.GetFileName(projectFilePath)}' has '{ProjectProperties.IsTestingPlatformApplication}' = '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}'.");
127+
project.SetProperty(ProjectProperties.TargetFramework, framework);
128+
project.ReevaluateIfNecessary();
129+
Logger.LogTrace(() => $"Loaded inner project '{Path.GetFileName(projectFilePath)}' has '{ProjectProperties.IsTestingPlatformApplication}' = '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}' (TFM: '{framework}').");
145130

146131
if (GetModuleFromProject(project) is { } module)
147132
{
148133
projects.Add(module);
149134
}
150135
}
151-
else
152-
{
153-
Logger.LogTrace(() => $"Loaded project '{Path.GetFileName(projectFilePath)}' has '{ProjectProperties.IsTestingPlatformApplication}' = '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}' (TFMs: '{targetFrameworks}').");
154-
155-
var frameworks = targetFrameworks.Split(CliConstants.SemiColon, StringSplitOptions.RemoveEmptyEntries);
156-
foreach (var framework in frameworks)
157-
{
158-
project.SetProperty(ProjectProperties.TargetFramework, framework);
159-
project.ReevaluateIfNecessary();
160-
161-
Logger.LogTrace(() => $"Loaded project '{Path.GetFileName(projectFilePath)}' has '{ProjectProperties.IsTestingPlatformApplication}' = '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}' (TFM: '{framework}').");
162-
163-
if (GetModuleFromProject(project) is { } module)
164-
{
165-
projects.Add(module);
166-
}
167-
}
168-
}
169136
}
170137

171138
return projects;
172139
}
173140

174-
175-
private static bool IsValidTargetFramework(Project project, string targetFramework)
176-
{
177-
string targetFrameworks = project.GetPropertyValue(ProjectProperties.TargetFrameworks);
178-
if (string.IsNullOrEmpty(targetFrameworks))
179-
{
180-
return project.GetPropertyValue(ProjectProperties.TargetFramework) == targetFramework;
181-
}
182-
183-
var frameworks = targetFrameworks.Split(CliConstants.SemiColon, StringSplitOptions.RemoveEmptyEntries);
184-
return frameworks.Contains(targetFramework);
185-
}
186-
187141
private static TestModule? GetModuleFromProject(Project project)
188142
{
189143
_ = bool.TryParse(project.GetPropertyValue(ProjectProperties.IsTestProject), out bool isTestProject);

0 commit comments

Comments
 (0)