66using Microsoft . Build . Evaluation ;
77using Microsoft . Build . Evaluation . Context ;
88using Microsoft . Build . Execution ;
9+ using Microsoft . Build . Framework ;
910using Microsoft . DotNet . Cli . Commands . Run ;
1011using Microsoft . DotNet . Cli . Commands . Run . LaunchSettings ;
1112using Microsoft . DotNet . Cli . Extensions ;
@@ -217,7 +218,7 @@ public static string GetRootDirectory(string solutionOrProjectFilePath)
217218 return string . IsNullOrEmpty ( fileDirectory ) ? Directory . GetCurrentDirectory ( ) : fileDirectory ;
218219 }
219220
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 )
221222 {
222223 var projects = new List < ParallelizableTestModuleGroupWithSequentialInnerModules > ( ) ;
223224 ProjectInstance projectInstance = EvaluateProject ( projectCollection , evaluationContext , projectFilePath , null ) ;
@@ -229,7 +230,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
229230
230231 if ( ! string . IsNullOrEmpty ( targetFramework ) || string . IsNullOrEmpty ( targetFrameworks ) )
231232 {
232- if ( GetModuleFromProject ( projectInstance , buildOptions ) is { } module )
233+ if ( GetModuleFromProject ( projectInstance , buildOptions , telemetryCentralLogger ) is { } module )
233234 {
234235 projects . Add ( new ParallelizableTestModuleGroupWithSequentialInnerModules ( module ) ) ;
235236 }
@@ -257,7 +258,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
257258 projectInstance = EvaluateProject ( projectCollection , evaluationContext , projectFilePath , framework ) ;
258259 Logger . LogTrace ( $ "Loaded inner project '{ Path . GetFileName ( projectFilePath ) } ' has '{ ProjectProperties . IsTestingPlatformApplication } ' = '{ projectInstance . GetPropertyValue ( ProjectProperties . IsTestingPlatformApplication ) } ' (TFM: '{ framework } ').") ;
259260
260- if ( GetModuleFromProject ( projectInstance , buildOptions ) is { } module )
261+ if ( GetModuleFromProject ( projectInstance , buildOptions , telemetryCentralLogger ) is { } module )
261262 {
262263 projects . Add ( new ParallelizableTestModuleGroupWithSequentialInnerModules ( module ) ) ;
263264 }
@@ -271,7 +272,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
271272 projectInstance = EvaluateProject ( projectCollection , evaluationContext , projectFilePath , framework ) ;
272273 Logger . LogTrace ( $ "Loaded inner project '{ Path . GetFileName ( projectFilePath ) } ' has '{ ProjectProperties . IsTestingPlatformApplication } ' = '{ projectInstance . GetPropertyValue ( ProjectProperties . IsTestingPlatformApplication ) } ' (TFM: '{ framework } ').") ;
273274
274- if ( GetModuleFromProject ( projectInstance , buildOptions ) is { } module )
275+ if ( GetModuleFromProject ( projectInstance , buildOptions , telemetryCentralLogger ) is { } module )
275276 {
276277 innerModules ??= new List < TestModule > ( ) ;
277278 innerModules . Add ( module ) ;
@@ -288,7 +289,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
288289 return projects ;
289290 }
290291
291- private static TestModule ? GetModuleFromProject ( ProjectInstance project , BuildOptions buildOptions )
292+ private static TestModule ? GetModuleFromProject ( ProjectInstance project , BuildOptions buildOptions , ILogger ? telemetryCentralLogger = null )
292293 {
293294 _ = bool . TryParse ( project . GetPropertyValue ( ProjectProperties . IsTestProject ) , out bool isTestProject ) ;
294295 _ = bool . TryParse ( project . GetPropertyValue ( ProjectProperties . IsTestingPlatformApplication ) , out bool isTestingPlatformApplication ) ;
@@ -306,7 +307,7 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
306307 RunProperties runProperties ;
307308 if ( isTestingPlatformApplication )
308309 {
309- runProperties = GetRunProperties ( project ) ;
310+ runProperties = GetRunProperties ( project , telemetryCentralLogger ) ;
310311
311312 // dotnet run throws the same if RunCommand is null or empty.
312313 // In dotnet test, we are additionally checking that RunCommand is not dll.
@@ -346,15 +347,15 @@ public static IEnumerable<ParallelizableTestModuleGroupWithSequentialInnerModule
346347
347348 return new TestModule ( runProperties , PathUtility . FixFilePath ( projectFullPath ) , targetFramework , isTestingPlatformApplication , launchSettings , project . GetPropertyValue ( ProjectProperties . TargetPath ) , rootVariableName ) ;
348349
349- static RunProperties GetRunProperties ( ProjectInstance project )
350+ static RunProperties GetRunProperties ( ProjectInstance project , ILogger ? telemetryCentralLogger )
350351 {
351352 // Build API cannot be called in parallel, even if the projects are different.
352353 // Otherwise, BuildManager in MSBuild will fail:
353354 // System.InvalidOperationException: The operation cannot be completed because a build is already in progress.
354355 // NOTE: BuildManager is singleton.
355356 lock ( s_buildLock )
356357 {
357- if ( ! project . BuildWithTelemetry ( s_computeRunArgumentsTarget ) )
358+ if ( ! project . BuildWithTelemetry ( s_computeRunArgumentsTarget , telemetryCentralLogger : telemetryCentralLogger ) )
358359 {
359360 throw new GracefulException ( CliCommandStrings . RunCommandEvaluationExceptionBuildFailed , s_computeRunArgumentsTarget [ 0 ] ) ;
360361 }
0 commit comments