@@ -95,7 +95,10 @@ public ProjectCacheService(
9595 /// <summary>
9696 /// Optimization which frontloads plugin initialization since we have an entire graph.
9797 /// </summary>
98- public void InitializePluginsForGraph ( ProjectGraph projectGraph , CancellationToken cancellationToken )
98+ public void InitializePluginsForGraph (
99+ ProjectGraph projectGraph ,
100+ ICollection < string > requestedTargets ,
101+ CancellationToken cancellationToken )
99102 {
100103 EnsureNotDisposed ( ) ;
101104
@@ -111,7 +114,7 @@ public void InitializePluginsForGraph(ProjectGraph projectGraph, CancellationTok
111114 foreach ( ProjectCacheDescriptor projectCacheDescriptor in GetProjectCacheDescriptors ( node . ProjectInstance ) )
112115 {
113116 // Intentionally fire-and-forget to asynchronously initialize the plugin. Any exceptions will bubble up later when querying.
114- _ = GetProjectCachePluginAsync ( projectCacheDescriptor , projectGraph , buildRequestConfiguration : null , cancellationToken )
117+ _ = GetProjectCachePluginAsync ( projectCacheDescriptor , projectGraph , buildRequestConfiguration : null , requestedTargets , cancellationToken )
115118 . ContinueWith ( t => { } , TaskContinuationOptions . ExecuteSynchronously | TaskContinuationOptions . OnlyOnFaulted ) ;
116119 }
117120 } ) ;
@@ -122,6 +125,7 @@ public void InitializePluginsForGraph(ProjectGraph projectGraph, CancellationTok
122125 public void InitializePluginsForVsScenario (
123126 IEnumerable < ProjectCacheDescriptor > projectCacheDescriptors ,
124127 BuildRequestConfiguration buildRequestConfiguration ,
128+ ICollection < string > requestedTargets ,
125129 CancellationToken cancellationToken )
126130 {
127131 EnsureNotDisposed ( ) ;
@@ -144,7 +148,7 @@ public void InitializePluginsForVsScenario(
144148 projectCacheDescriptor =>
145149 {
146150 // Intentionally fire-and-forget to asynchronously initialize the plugin. Any exceptions will bubble up later when querying.
147- _ = GetProjectCachePluginAsync ( projectCacheDescriptor , projectGraph : null , buildRequestConfiguration , cancellationToken )
151+ _ = GetProjectCachePluginAsync ( projectCacheDescriptor , projectGraph : null , buildRequestConfiguration , requestedTargets , cancellationToken )
148152 . ContinueWith ( t => { } , TaskContinuationOptions . ExecuteSynchronously | TaskContinuationOptions . OnlyOnFaulted ) ;
149153 } ) ;
150154 } ,
@@ -155,12 +159,13 @@ private Task<ProjectCachePlugin> GetProjectCachePluginAsync(
155159 ProjectCacheDescriptor projectCacheDescriptor ,
156160 ProjectGraph ? projectGraph ,
157161 BuildRequestConfiguration ? buildRequestConfiguration ,
162+ ICollection < string > requestedTargets ,
158163 CancellationToken cancellationToken )
159164 => _projectCachePlugins . GetOrAdd (
160165 projectCacheDescriptor ,
161166 // The use of Lazy is because ConcurrentDictionary doesn't guarantee the value factory executes only once if there are multiple simultaneous callers,
162167 // so this ensures that CreateAndInitializePluginAsync is only called exactly once.
163- descriptor => new Lazy < Task < ProjectCachePlugin > > ( ( ) => CreateAndInitializePluginAsync ( descriptor , projectGraph , buildRequestConfiguration , cancellationToken ) ) )
168+ descriptor => new Lazy < Task < ProjectCachePlugin > > ( ( ) => CreateAndInitializePluginAsync ( descriptor , projectGraph , buildRequestConfiguration , requestedTargets , cancellationToken ) ) )
164169 . Value ;
165170
166171 private IEnumerable < ProjectCacheDescriptor > GetProjectCacheDescriptors ( ProjectInstance projectInstance )
@@ -189,6 +194,7 @@ private async Task<ProjectCachePlugin> CreateAndInitializePluginAsync(
189194 ProjectCacheDescriptor projectCacheDescriptor ,
190195 ProjectGraph ? projectGraph ,
191196 BuildRequestConfiguration ? buildRequestConfiguration ,
197+ ICollection < string > requestedTargets ,
192198 CancellationToken cancellationToken )
193199 {
194200 BuildEventContext buildEventContext = BuildEventContext . Invalid ;
@@ -241,6 +247,9 @@ private async Task<ProjectCachePlugin> CreateAndInitializePluginAsync(
241247 ? GetGraphEntryPoints ( buildRequestConfiguration )
242248 : null ;
243249
250+ // In practice, the underlying type of the ICollection is a List<string> so attempt to cast first
251+ IReadOnlyList < string > requestedTargetsList = requestedTargets as List < string > ?? requestedTargets . ToList ( ) ;
252+
244253 _loggingService . LogComment ( buildEventContext , MessageImportance . High , "LoadingProjectCachePlugin" , pluginTypeName ) ;
245254 MSBuildEventSource . Log . ProjectCacheBeginBuildStart ( pluginTypeName ) ;
246255
@@ -250,6 +259,7 @@ await pluginInstance.BeginBuildAsync(
250259 new CacheContext (
251260 projectCacheDescriptor . PluginSettings ,
252261 DefaultMSBuildFileSystem . Instance ,
262+ requestedTargetsList ,
253263 projectGraph ,
254264 graphEntryPoints ) ,
255265 pluginLogger ,
@@ -517,7 +527,8 @@ private async Task<CacheResult> GetCacheResultAsync(BuildRequestData buildReques
517527 continue ;
518528 }
519529
520- ProjectCachePlugin plugin = await GetProjectCachePluginAsync ( projectCacheDescriptor , projectGraph : null , buildRequestConfiguration , cancellationToken ) ;
530+ ICollection < string > requestedTargetsList = buildRequestConfiguration . RequestedTargets as ICollection < string > ?? buildRequestConfiguration . RequestedTargets . ToList ( ) ;
531+ ProjectCachePlugin plugin = await GetProjectCachePluginAsync ( projectCacheDescriptor , projectGraph : null , buildRequestConfiguration , requestedTargetsList , cancellationToken ) ;
521532 try
522533 {
523534 // Rethrow any initialization exception.
0 commit comments