6
6
using Microsoft . Build . Evaluation ;
7
7
using Microsoft . Build . Evaluation . Context ;
8
8
using Microsoft . Build . Execution ;
9
+ using Microsoft . Build . Framework ;
9
10
using Microsoft . DotNet . Cli . Commands . Run ;
10
11
using Microsoft . DotNet . Cli . Commands . Run . LaunchSettings ;
11
12
using Microsoft . DotNet . Cli . Extensions ;
@@ -217,7 +218,7 @@ public static string GetRootDirectory(string solutionOrProjectFilePath)
217
218
return string . IsNullOrEmpty ( fileDirectory ) ? Directory . GetCurrentDirectory ( ) : fileDirectory ;
218
219
}
219
220
220
- public static IEnumerable < ParallelizableTestModuleGroupWithSequentialInnerModules > GetProjectProperties ( string projectFilePath , ProjectCollection projectCollection , EvaluationContext evaluationContext , BuildOptions buildOptions )
221
+ public static IEnumerable < ParallelizableTestModuleGroupWithSequentialInnerModules > GetProjectProperties ( string projectFilePath , ProjectCollection projectCollection , EvaluationContext evaluationContext , BuildOptions buildOptions , ILogger ? telemetryCentralLogger = null )
221
222
{
222
223
var projects = new List < ParallelizableTestModuleGroupWithSequentialInnerModules > ( ) ;
223
224
ProjectInstance projectInstance = EvaluateProject ( projectCollection , evaluationContext , projectFilePath , null ) ;
@@ -229,7 +230,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
229
230
230
231
if ( ! string . IsNullOrEmpty ( targetFramework ) || string . IsNullOrEmpty ( targetFrameworks ) )
231
232
{
232
- if ( GetModuleFromProject ( projectInstance , buildOptions ) is { } module )
233
+ if ( GetModuleFromProject ( projectInstance , buildOptions , telemetryCentralLogger ) is { } module )
233
234
{
234
235
projects . Add ( new ParallelizableTestModuleGroupWithSequentialInnerModules ( module ) ) ;
235
236
}
@@ -257,7 +258,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
257
258
projectInstance = EvaluateProject ( projectCollection , evaluationContext , projectFilePath , framework ) ;
258
259
Logger . LogTrace ( $ "Loaded inner project '{ Path . GetFileName ( projectFilePath ) } ' has '{ ProjectProperties . IsTestingPlatformApplication } ' = '{ projectInstance . GetPropertyValue ( ProjectProperties . IsTestingPlatformApplication ) } ' (TFM: '{ framework } ').") ;
259
260
260
- if ( GetModuleFromProject ( projectInstance , buildOptions ) is { } module )
261
+ if ( GetModuleFromProject ( projectInstance , buildOptions , telemetryCentralLogger ) is { } module )
261
262
{
262
263
projects . Add ( new ParallelizableTestModuleGroupWithSequentialInnerModules ( module ) ) ;
263
264
}
@@ -271,7 +272,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
271
272
projectInstance = EvaluateProject ( projectCollection , evaluationContext , projectFilePath , framework ) ;
272
273
Logger . LogTrace ( $ "Loaded inner project '{ Path . GetFileName ( projectFilePath ) } ' has '{ ProjectProperties . IsTestingPlatformApplication } ' = '{ projectInstance . GetPropertyValue ( ProjectProperties . IsTestingPlatformApplication ) } ' (TFM: '{ framework } ').") ;
273
274
274
- if ( GetModuleFromProject ( projectInstance , buildOptions ) is { } module )
275
+ if ( GetModuleFromProject ( projectInstance , buildOptions , telemetryCentralLogger ) is { } module )
275
276
{
276
277
innerModules ??= new List < TestModule > ( ) ;
277
278
innerModules . Add ( module ) ;
@@ -288,7 +289,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
288
289
return projects ;
289
290
}
290
291
291
- private static TestModule ? GetModuleFromProject ( ProjectInstance project , BuildOptions buildOptions )
292
+ private static TestModule ? GetModuleFromProject ( ProjectInstance project , BuildOptions buildOptions , ILogger ? telemetryCentralLogger = null )
292
293
{
293
294
_ = bool . TryParse ( project . GetPropertyValue ( ProjectProperties . IsTestProject ) , out bool isTestProject ) ;
294
295
_ = bool . TryParse ( project . GetPropertyValue ( ProjectProperties . IsTestingPlatformApplication ) , out bool isTestingPlatformApplication ) ;
@@ -306,7 +307,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
306
307
RunProperties runProperties ;
307
308
if ( isTestingPlatformApplication )
308
309
{
309
- runProperties = GetRunProperties ( project ) ;
310
+ runProperties = GetRunProperties ( project , telemetryCentralLogger ) ;
310
311
311
312
// dotnet run throws the same if RunCommand is null or empty.
312
313
// In dotnet test, we are additionally checking that RunCommand is not dll.
@@ -346,15 +347,15 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
346
347
347
348
return new TestModule ( runProperties , PathUtility . FixFilePath ( projectFullPath ) , targetFramework , isTestingPlatformApplication , launchSettings , project . GetPropertyValue ( ProjectProperties . TargetPath ) , rootVariableName ) ;
348
349
349
- static RunProperties GetRunProperties ( ProjectInstance project )
350
+ static RunProperties GetRunProperties ( ProjectInstance project , ILogger ? telemetryCentralLogger )
350
351
{
351
352
// Build API cannot be called in parallel, even if the projects are different.
352
353
// Otherwise, BuildManager in MSBuild will fail:
353
354
// System.InvalidOperationException: The operation cannot be completed because a build is already in progress.
354
355
// NOTE: BuildManager is singleton.
355
356
lock ( s_buildLock )
356
357
{
357
- if ( ! project . BuildWithTelemetry ( s_computeRunArgumentsTarget ) )
358
+ if ( ! project . BuildWithTelemetry ( s_computeRunArgumentsTarget , telemetryCentralLogger : telemetryCentralLogger ) )
358
359
{
359
360
throw new GracefulException ( CliCommandStrings . RunCommandEvaluationExceptionBuildFailed , s_computeRunArgumentsTarget [ 0 ] ) ;
360
361
}
0 commit comments