@@ -334,7 +334,7 @@ private async Task BeginBuildInnerAsync(CacheContext context, PluginLoggerBase l
334334 if ( Settings . GetResultsForUnqueriedDependencies )
335335 {
336336 ConcurrentDictionary < NodeContext , Lazy < Task < CacheResult > > > cacheResults = new ( concurrencyLevel : Environment . ProcessorCount , _nodeContexts . Count ) ;
337- _getCacheResultAsync = ( nodeContext , logger , cancellationToken ) => GetCacheResultRecursivelyAsync ( cacheResults , nodeContext , logger , cancellationToken ) ;
337+ _getCacheResultAsync = ( nodeContext , logger , cancellationToken ) => GetCacheResultRecursivelyAsync ( cacheResults , nodeContext , materializeOutputs : true , logger , cancellationToken ) ;
338338 }
339339 else
340340 {
@@ -405,6 +405,7 @@ private async Task<CacheResult> GetCacheResultInnerAsync(BuildRequestData buildR
405405 private async Task < CacheResult > GetCacheResultRecursivelyAsync (
406406 ConcurrentDictionary < NodeContext , Lazy < Task < CacheResult > > > cacheResults ,
407407 NodeContext nodeContext ,
408+ bool materializeOutputs ,
408409 PluginLoggerBase logger ,
409410 CancellationToken cancellationToken )
410411 {
@@ -413,12 +414,21 @@ private async Task<CacheResult> GetCacheResultRecursivelyAsync(
413414 return await cacheResults . GetOrAdd ( nodeContext , new Lazy < Task < CacheResult > > (
414415 async ( ) =>
415416 {
417+ bool isOuterBuild = nodeContext . ProjectInstance . IsOuterBuild ( ) ;
418+
416419 foreach ( NodeContext dependency in nodeContext . Dependencies )
417420 {
418421 if ( dependency . BuildResult == null )
419422 {
423+ // When querying recursively, avoid materializing the outputs. That node was never directly queried, so its outputs
424+ // are not desired from the caller. Note that there is an assumption that the node won't be queried directly later
425+ // as that would break the expected "bottom-up" build order of graph builds.
426+ // Special-case the outer build of a multitargeting project which dependencies on the inner builds for which we do
427+ // want the outputs.
428+ bool materializeOutputs = isOuterBuild && dependency . ProjectInstance . IsInnerBuild ( ) ;
429+
420430 logger . LogMessage ( $ "Querying cache for missing build result for dependency '{ dependency . Id } '") ;
421- CacheResult dependencyResult = await GetCacheResultRecursivelyAsync ( cacheResults , dependency , logger , cancellationToken ) ;
431+ CacheResult dependencyResult = await GetCacheResultRecursivelyAsync ( cacheResults , dependency , materializeOutputs , logger , cancellationToken ) ;
422432 logger . LogMessage ( $ "Dependency '{ dependency . Id } ' cache result: '{ dependencyResult . ResultType } '") ;
423433
424434 if ( dependencyResult . ResultType != CacheResultType . CacheHit )
@@ -430,7 +440,7 @@ private async Task<CacheResult> GetCacheResultRecursivelyAsync(
430440 }
431441 }
432442
433- return await GetCacheResultSingleAsync ( nodeContext , logger , cancellationToken ) ;
443+ return await GetCacheResultSingleAsync ( nodeContext , materializeOutputs , logger , cancellationToken ) ;
434444 } ) ) . Value ;
435445 }
436446
@@ -446,10 +456,10 @@ private async Task<CacheResult> GetCacheResultNonRecursiveAsync(NodeContext node
446456 }
447457 }
448458
449- return await GetCacheResultSingleAsync ( nodeContext , logger , cancellationToken ) ;
459+ return await GetCacheResultSingleAsync ( nodeContext , materializeOutputs : true , logger , cancellationToken ) ;
450460 }
451461
452- private async Task < CacheResult > GetCacheResultSingleAsync ( NodeContext nodeContext , PluginLoggerBase logger , CancellationToken cancellationToken )
462+ private async Task < CacheResult > GetCacheResultSingleAsync ( NodeContext nodeContext , bool materializeOutputs , PluginLoggerBase logger , CancellationToken cancellationToken )
453463 {
454464 if ( ! Initialized )
455465 {
@@ -458,7 +468,7 @@ private async Task<CacheResult> GetCacheResultSingleAsync(NodeContext nodeContex
458468
459469 nodeContext . SetStartTime ( ) ;
460470
461- ( PathSet ? pathSet , NodeBuildResult ? nodeBuildResult ) = await _cacheClient . GetNodeAsync ( nodeContext , cancellationToken ) ;
471+ ( PathSet ? pathSet , NodeBuildResult ? nodeBuildResult ) = await _cacheClient . GetNodeAsync ( nodeContext , materializeOutputs , cancellationToken ) ;
462472 if ( nodeBuildResult is null )
463473 {
464474 Interlocked . Increment ( ref _cacheMissCount ) ;
0 commit comments