1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System . CommandLine ;
4
5
using System . Diagnostics ;
5
6
using Microsoft . Build . Evaluation ;
6
7
using Microsoft . Build . Execution ;
@@ -147,7 +148,7 @@ public static string GetRootDirectory(string solutionOrProjectFilePath)
147
148
return string . IsNullOrEmpty ( fileDirectory ) ? Directory . GetCurrentDirectory ( ) : fileDirectory ;
148
149
}
149
150
150
- public static IEnumerable < ParallelizableTestModuleGroupWithSequentialInnerModules > GetProjectProperties ( string projectFilePath , ProjectCollection projectCollection , bool noLaunchProfile )
151
+ public static IEnumerable < ParallelizableTestModuleGroupWithSequentialInnerModules > GetProjectProperties ( string projectFilePath , ProjectCollection projectCollection , BuildOptions buildOptions )
151
152
{
152
153
var projects = new List < ParallelizableTestModuleGroupWithSequentialInnerModules > ( ) ;
153
154
ProjectInstance projectInstance = EvaluateProject ( projectCollection , projectFilePath , null ) ;
@@ -159,7 +160,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
159
160
160
161
if ( ! string . IsNullOrEmpty ( targetFramework ) || string . IsNullOrEmpty ( targetFrameworks ) )
161
162
{
162
- if ( GetModuleFromProject ( projectInstance , projectCollection . Loggers , noLaunchProfile ) is { } module )
163
+ if ( GetModuleFromProject ( projectInstance , projectCollection . Loggers , buildOptions ) is { } module )
163
164
{
164
165
projects . Add ( new ParallelizableTestModuleGroupWithSequentialInnerModules ( module ) ) ;
165
166
}
@@ -187,7 +188,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
187
188
projectInstance = EvaluateProject ( projectCollection , projectFilePath , framework ) ;
188
189
Logger . LogTrace ( ( ) => $ "Loaded inner project '{ Path . GetFileName ( projectFilePath ) } ' has '{ ProjectProperties . IsTestingPlatformApplication } ' = '{ projectInstance . GetPropertyValue ( ProjectProperties . IsTestingPlatformApplication ) } ' (TFM: '{ framework } ').") ;
189
190
190
- if ( GetModuleFromProject ( projectInstance , projectCollection . Loggers , noLaunchProfile ) is { } module )
191
+ if ( GetModuleFromProject ( projectInstance , projectCollection . Loggers , buildOptions ) is { } module )
191
192
{
192
193
projects . Add ( new ParallelizableTestModuleGroupWithSequentialInnerModules ( module ) ) ;
193
194
}
@@ -201,7 +202,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
201
202
projectInstance = EvaluateProject ( projectCollection , projectFilePath , framework ) ;
202
203
Logger . LogTrace ( ( ) => $ "Loaded inner project '{ Path . GetFileName ( projectFilePath ) } ' has '{ ProjectProperties . IsTestingPlatformApplication } ' = '{ projectInstance . GetPropertyValue ( ProjectProperties . IsTestingPlatformApplication ) } ' (TFM: '{ framework } ').") ;
203
204
204
- if ( GetModuleFromProject ( projectInstance , projectCollection . Loggers , noLaunchProfile ) is { } module )
205
+ if ( GetModuleFromProject ( projectInstance , projectCollection . Loggers , buildOptions ) is { } module )
205
206
{
206
207
innerModules ??= new List < TestModule > ( ) ;
207
208
innerModules . Add ( module ) ;
@@ -218,7 +219,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
218
219
return projects ;
219
220
}
220
221
221
- private static TestModule ? GetModuleFromProject ( ProjectInstance project , ICollection < ILogger > ? loggers , bool noLaunchProfile )
222
+ private static TestModule ? GetModuleFromProject ( ProjectInstance project , ICollection < ILogger > ? loggers , BuildOptions buildOptions )
222
223
{
223
224
_ = bool . TryParse ( project . GetPropertyValue ( ProjectProperties . IsTestProject ) , out bool isTestProject ) ;
224
225
_ = bool . TryParse ( project . GetPropertyValue ( ProjectProperties . IsTestingPlatformApplication ) , out bool isTestingPlatformApplication ) ;
@@ -248,9 +249,19 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
248
249
string projectFullPath = project . GetPropertyValue ( ProjectProperties . ProjectFullPath ) ;
249
250
250
251
// TODO: Support --launch-profile and pass it here.
251
- var launchSettings = TryGetLaunchProfileSettings ( Path . GetDirectoryName ( projectFullPath ) ! , Path . GetFileNameWithoutExtension ( projectFullPath ) , project . GetPropertyValue ( ProjectProperties . AppDesignerFolder ) , noLaunchProfile , profileName : null ) ;
252
+ var launchSettings = TryGetLaunchProfileSettings ( Path . GetDirectoryName ( projectFullPath ) ! , Path . GetFileNameWithoutExtension ( projectFullPath ) , project . GetPropertyValue ( ProjectProperties . AppDesignerFolder ) , buildOptions , profileName : null ) ;
252
253
253
- return new TestModule ( runProperties , PathUtility . FixFilePath ( projectFullPath ) , targetFramework , isTestingPlatformApplication , isTestProject , launchSettings , project . GetPropertyValue ( ProjectProperties . TargetPath ) ) ;
254
+ var rootVariableName = EnvironmentVariableNames . TryGetDotNetRootArchVariableName (
255
+ project . GetPropertyValue ( "RuntimeIdentifier" ) ,
256
+ project . GetPropertyValue ( "DefaultAppHostRuntimeIdentifier" ) ) ;
257
+
258
+ if ( rootVariableName is not null && Environment . GetEnvironmentVariable ( rootVariableName ) != null )
259
+ {
260
+ // If already set, we do not override it.
261
+ rootVariableName = null ;
262
+ }
263
+
264
+ return new TestModule ( runProperties , PathUtility . FixFilePath ( projectFullPath ) , targetFramework , isTestingPlatformApplication , isTestProject , launchSettings , project . GetPropertyValue ( ProjectProperties . TargetPath ) , rootVariableName ) ;
254
265
255
266
static RunProperties GetRunProperties ( ProjectInstance project , ICollection < ILogger > ? loggers )
256
267
{
@@ -270,9 +281,9 @@ static RunProperties GetRunProperties(ProjectInstance project, ICollection<ILogg
270
281
}
271
282
}
272
283
273
- private static ProjectLaunchSettingsModel ? TryGetLaunchProfileSettings ( string projectDirectory , string projectNameWithoutExtension , string appDesignerFolder , bool noLaunchProfile , string ? profileName )
284
+ private static ProjectLaunchSettingsModel ? TryGetLaunchProfileSettings ( string projectDirectory , string projectNameWithoutExtension , string appDesignerFolder , BuildOptions buildOptions , string ? profileName )
274
285
{
275
- if ( noLaunchProfile )
286
+ if ( buildOptions . NoLaunchProfile )
276
287
{
277
288
return null ;
278
289
}
@@ -299,6 +310,12 @@ static RunProperties GetRunProperties(ProjectInstance project, ICollection<ILogg
299
310
return null ;
300
311
}
301
312
313
+ // If buildOptions.Verbosity is null, we still want to print the message.
314
+ if ( buildOptions . Verbosity != VerbosityOptions . quiet )
315
+ {
316
+ Reporter . Output . WriteLine ( string . Format ( CliCommandStrings . UsingLaunchSettingsFromMessage , launchSettingsPath ) ) ;
317
+ }
318
+
302
319
var result = LaunchSettingsManager . TryApplyLaunchSettings ( launchSettingsPath , profileName ) ;
303
320
if ( ! result . Success )
304
321
{
0 commit comments