@@ -110,7 +110,7 @@ protected void ShutdownAllNodes(long hostHandshake, long clientHandshake, NodeCo
110110 // INodePacketFactory
111111 INodePacketFactory factory = new NodePacketFactory ( ) ;
112112
113- List < Process > nodeProcesses = GetPossibleRunningNodes ( ) ;
113+ List < Process > nodeProcesses = GetPossibleRunningNodes ( ) . nodeProcesses ;
114114
115115 // Find proper MSBuildTaskHost executable name
116116 string msbuildtaskhostExeName = NodeProviderOutOfProcTaskHost . TaskHostNameForClr2TaskHost ;
@@ -167,10 +167,10 @@ protected NodeContext GetNode(string msbuildLocation, string commandLineArgs, in
167167 // Try to connect to idle nodes if node reuse is enabled.
168168 if ( _componentHost . BuildParameters . EnableNodeReuse )
169169 {
170- var candidateProcesses = GetPossibleRunningNodes ( msbuildLocation ) ;
170+ ( string expectedProcessName , List < Process > processes ) runningNodesTuple = GetPossibleRunningNodes ( msbuildLocation ) ;
171171
172- CommunicationsUtilities . Trace ( "Attempting to connect to each existing msbuild.exe process in turn to establish node {0}..." , nodeId ) ;
173- foreach ( Process nodeProcess in candidateProcesses )
172+ CommunicationsUtilities . Trace ( "Attempting to connect to each existing {1} process in turn to establish node {0}..." , nodeId , runningNodesTuple . expectedProcessName ) ;
173+ foreach ( Process nodeProcess in runningNodesTuple . processes )
174174 {
175175 if ( nodeProcess . Id == Process . GetCurrentProcess ( ) . Id )
176176 {
@@ -253,7 +253,15 @@ protected NodeContext GetNode(string msbuildLocation, string commandLineArgs, in
253253 return null ;
254254 }
255255
256- private List < Process > GetPossibleRunningNodes ( string msbuildLocation = null )
256+ /// <summary>
257+ /// Finds processes named after either msbuild or msbuildtaskhost.
258+ /// </summary>
259+ /// <param name="msbuildLocation"></param>
260+ /// <returns>
261+ /// Item 1 is the name of the process being searched for.
262+ /// Item 2 is the list of processes themselves.
263+ /// </returns>
264+ private ( string expectedProcessName , List < Process > nodeProcesses ) GetPossibleRunningNodes ( string msbuildLocation = null )
257265 {
258266 if ( String . IsNullOrEmpty ( msbuildLocation ) )
259267 {
@@ -267,7 +275,7 @@ private List<Process> GetPossibleRunningNodes(string msbuildLocation = null)
267275 // Trivial sort to try to prefer most recently used nodes
268276 nodeProcesses . Sort ( ( left , right ) => left . Id - right . Id ) ;
269277
270- return nodeProcesses ;
278+ return ( expectedProcessName , nodeProcesses ) ;
271279 }
272280
273281 /// <summary>
@@ -475,7 +483,7 @@ private int LaunchNode(string msbuildLocation, string commandLineArgs)
475483 throw new NodeFailedToLaunchException ( ex ) ;
476484 }
477485
478- CommunicationsUtilities . Trace ( "Successfully launched msbuild.exe node with PID {0}" , process . Id ) ;
486+ CommunicationsUtilities . Trace ( "Successfully launched {1} node with PID {0}" , process . Id , exeName ) ;
479487 return process . Id ;
480488 }
481489 else
@@ -533,7 +541,7 @@ out processInfo
533541 NativeMethodsShared . CloseHandle ( processInfo . hThread ) ;
534542 }
535543
536- CommunicationsUtilities . Trace ( "Successfully launched msbuild.exe node with PID {0}" , childProcessId ) ;
544+ CommunicationsUtilities . Trace ( "Successfully launched {1} node with PID {0}" , childProcessId , exeName ) ;
537545 return childProcessId ;
538546 }
539547 }
0 commit comments