|
3 | 3 |
|
4 | 4 | using Microsoft.Build.Evaluation; |
5 | 5 | using Microsoft.DotNet.Cli.Utils; |
| 6 | +using Microsoft.DotNet.Tools; |
6 | 7 | using Microsoft.DotNet.Tools.Test; |
7 | 8 | using NuGet.Packaging; |
8 | 9 | using LocalizableStrings = Microsoft.DotNet.Tools.Test.LocalizableStrings; |
@@ -104,85 +105,39 @@ public static IEnumerable<TestModule> GetProjectProperties(string projectFilePat |
104 | 105 | { |
105 | 106 | var projects = new List<TestModule>(); |
106 | 107 |
|
107 | | - var globalPropertiesWithoutTargetFramework = new Dictionary<string, string>(globalProperties); |
108 | | - globalPropertiesWithoutTargetFramework.Remove(ProjectProperties.TargetFramework); |
109 | 108 |
|
110 | | - var project = projectCollection.LoadProject(projectFilePath, globalPropertiesWithoutTargetFramework, null); |
| 109 | + var project = projectCollection.LoadProject(projectFilePath, globalProperties, null); |
111 | 110 |
|
112 | | - // Check if TargetFramework is specified in global properties |
113 | | - if (globalProperties.TryGetValue(ProjectProperties.TargetFramework, out string targetFramework)) |
114 | | - { |
115 | | - Logger.LogTrace(() => $"Loaded project '{Path.GetFileName(projectFilePath)}' with global property TargetFramework '{targetFramework}'."); |
116 | | - |
117 | | - if (IsValidTargetFramework(project, targetFramework)) |
118 | | - { |
119 | | - 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)}'."); |
120 | 114 |
|
121 | | - project.SetProperty(ProjectProperties.TargetFramework, targetFramework); |
122 | | - project.ReevaluateIfNecessary(); |
123 | | - |
124 | | - Logger.LogTrace(() => $"Project '{Path.GetFileName(projectFilePath)}' with TargetFramework '{targetFramework}': after re-evaluation '{ProjectProperties.IsTestingPlatformApplication}' is '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}'."); |
125 | | - |
126 | | - if (GetModuleFromProject(project) is { } module) |
127 | | - { |
128 | | - projects.Add(module); |
129 | | - } |
130 | | - } |
131 | | - else |
| 115 | + if (!string.IsNullOrEmpty(targetFramework) || string.IsNullOrEmpty(targetFrameworks)) |
| 116 | + { |
| 117 | + if (GetModuleFromProject(project) is { } module) |
132 | 118 | { |
133 | | - // TODO: When can this happen? Should we explicitly error? |
134 | | - Logger.LogTrace(() => $"Project '{Path.GetFileName(projectFilePath)}' with TargetFramework '{targetFramework}' was considered invalid."); |
| 119 | + projects.Add(module); |
135 | 120 | } |
136 | 121 | } |
137 | 122 | else |
138 | 123 | { |
139 | | - string targetFrameworks = project.GetPropertyValue(ProjectProperties.TargetFrameworks); |
140 | | - |
141 | | - if (string.IsNullOrEmpty(targetFrameworks)) |
| 124 | + var frameworks = targetFrameworks.Split(CliConstants.SemiColon, StringSplitOptions.RemoveEmptyEntries); |
| 125 | + foreach (var framework in frameworks) |
142 | 126 | { |
143 | | - 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}')."); |
144 | 130 |
|
145 | 131 | if (GetModuleFromProject(project) is { } module) |
146 | 132 | { |
147 | 133 | projects.Add(module); |
148 | 134 | } |
149 | 135 | } |
150 | | - else |
151 | | - { |
152 | | - Logger.LogTrace(() => $"Loaded project '{Path.GetFileName(projectFilePath)}' has '{ProjectProperties.IsTestingPlatformApplication}' = '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}' (TFMs: '{targetFrameworks}')."); |
153 | | - |
154 | | - var frameworks = targetFrameworks.Split(CliConstants.SemiColon, StringSplitOptions.RemoveEmptyEntries); |
155 | | - foreach (var framework in frameworks) |
156 | | - { |
157 | | - project.SetProperty(ProjectProperties.TargetFramework, framework); |
158 | | - project.ReevaluateIfNecessary(); |
159 | | - |
160 | | - Logger.LogTrace(() => $"Loaded project '{Path.GetFileName(projectFilePath)}' has '{ProjectProperties.IsTestingPlatformApplication}' = '{project.GetPropertyValue(ProjectProperties.IsTestingPlatformApplication)}' (TFM: '{framework}')."); |
161 | | - |
162 | | - if (GetModuleFromProject(project) is { } module) |
163 | | - { |
164 | | - projects.Add(module); |
165 | | - } |
166 | | - } |
167 | | - } |
168 | 136 | } |
169 | 137 |
|
170 | 138 | return projects; |
171 | 139 | } |
172 | 140 |
|
173 | | - |
174 | | - private static bool IsValidTargetFramework(Project project, string targetFramework) |
175 | | - { |
176 | | - string targetFrameworks = project.GetPropertyValue(ProjectProperties.TargetFrameworks); |
177 | | - if (string.IsNullOrEmpty(targetFrameworks)) |
178 | | - { |
179 | | - return project.GetPropertyValue(ProjectProperties.TargetFramework) == targetFramework; |
180 | | - } |
181 | | - |
182 | | - var frameworks = targetFrameworks.Split(CliConstants.SemiColon, StringSplitOptions.RemoveEmptyEntries); |
183 | | - return frameworks.Contains(targetFramework); |
184 | | - } |
185 | | - |
186 | 141 | private static TestModule? GetModuleFromProject(Project project) |
187 | 142 | { |
188 | 143 | _ = bool.TryParse(project.GetPropertyValue(ProjectProperties.IsTestProject), out bool isTestProject); |
@@ -211,8 +166,8 @@ private static string GetExecutablePath(Project project) |
211 | 166 | string targetFrameworkIdentifier = project.GetPropertyValue(ProjectProperties.TargetFrameworkIdentifier); |
212 | 167 |
|
213 | 168 | if (targetFrameworkIdentifier.Equals(CliConstants.NetCoreIdentifier, StringComparison.OrdinalIgnoreCase) && |
214 | | - isExecutable && |
215 | | - useAppHost) |
| 169 | + isExecutable && |
| 170 | + useAppHost) |
216 | 171 | { |
217 | 172 | string targetDir = project.GetPropertyValue(ProjectProperties.TargetDir); |
218 | 173 | string assemblyName = project.GetPropertyValue(ProjectProperties.AssemblyName); |
|
0 commit comments