@@ -82,7 +82,7 @@ public BuildManager_Tests(ITestOutputHelper output)
8282 EnableNodeReuse = false
8383 } ;
8484 _buildManager = new BuildManager ( ) ;
85- _projectCollection = new ProjectCollection ( ) ;
85+ _projectCollection = new ProjectCollection ( globalProperties : null , _parameters . Loggers , ToolsetDefinitionLocations . Default ) ;
8686
8787 _env = TestEnvironment . Create ( output ) ;
8888 _inProcEnvCheckTransientEnvironmentVariable = _env . SetEnvironmentVariable ( "MSBUILDINPROCENVCHECK" , "1" ) ;
@@ -137,8 +137,8 @@ public void SimpleBuild()
137137 _logger . AssertLogContains ( "[success]" ) ;
138138 Assert . Single ( _logger . ProjectStartedEvents ) ;
139139
140- ProjectStartedEventArgs projectStartedEvent = _logger . ProjectStartedEvents [ 0 ] ;
141- Dictionary < string , string > properties = ExtractProjectStartedPropertyList ( projectStartedEvent . Properties ) ;
140+ ProjectEvaluationFinishedEventArgs evalFinishedEvent = _logger . EvaluationFinishedEvents [ 0 ] ;
141+ Dictionary < string , string > properties = ExtractProjectStartedPropertyList ( evalFinishedEvent . Properties ) ;
142142
143143 Assert . True ( properties . TryGetValue ( "InitialProperty1" , out string propertyValue ) ) ;
144144 Assert . Equal ( "InitialProperty1" , propertyValue ) ;
@@ -254,8 +254,8 @@ public void SimpleGraphBuild()
254254 _logger . AssertLogContains ( "[success]" ) ;
255255 _logger . ProjectStartedEvents . Count . ShouldBe ( 1 ) ;
256256
257- ProjectStartedEventArgs projectStartedEvent = _logger . ProjectStartedEvents [ 0 ] ;
258- Dictionary < string , string > properties = ExtractProjectStartedPropertyList ( projectStartedEvent . Properties ) ;
257+ ProjectEvaluationFinishedEventArgs evalFinishedEvent = _logger . EvaluationFinishedEvents [ 0 ] ;
258+ Dictionary < string , string > properties = ExtractProjectStartedPropertyList ( evalFinishedEvent . Properties ) ;
259259
260260 properties . TryGetValue ( "InitialProperty1" , out string propertyValue ) . ShouldBeTrue ( ) ;
261261 propertyValue . ShouldBe ( "InitialProperty1" , StringCompareShould . IgnoreCase ) ;
@@ -571,8 +571,8 @@ public void InProcForwardPropertiesFromChild()
571571 _logger . AssertLogContains ( "[success]" ) ;
572572 Assert . Single ( _logger . ProjectStartedEvents ) ;
573573
574- ProjectStartedEventArgs projectStartedEvent = _logger . ProjectStartedEvents [ 0 ] ;
575- Dictionary < string , string > properties = ExtractProjectStartedPropertyList ( projectStartedEvent . Properties ) ;
574+ ProjectEvaluationFinishedEventArgs evalFinishedEvent = _logger . EvaluationFinishedEvents [ 0 ] ;
575+ Dictionary < string , string > properties = ExtractProjectStartedPropertyList ( evalFinishedEvent . Properties ) ;
576576
577577 Assert . True ( properties . TryGetValue ( "InitialProperty1" , out string propertyValue ) ) ;
578578 Assert . Equal ( "InitialProperty1" , propertyValue ) ;
@@ -611,8 +611,8 @@ public void InProcMsBuildForwardAllPropertiesFromChild()
611611 _logger . AssertLogContains ( "[success]" ) ;
612612 Assert . Single ( _logger . ProjectStartedEvents ) ;
613613
614- ProjectStartedEventArgs projectStartedEvent = _logger . ProjectStartedEvents [ 0 ] ;
615- Dictionary < string , string > properties = ExtractProjectStartedPropertyList ( projectStartedEvent . Properties ) ;
614+ ProjectEvaluationFinishedEventArgs evalFinishedEvent = _logger . EvaluationFinishedEvents [ 0 ] ;
615+ Dictionary < string , string > properties = ExtractProjectStartedPropertyList ( evalFinishedEvent . Properties ) ;
616616
617617 Assert . True ( properties . TryGetValue ( "InitialProperty1" , out string propertyValue ) ) ;
618618 Assert . Equal ( "InitialProperty1" , propertyValue ) ;
@@ -655,8 +655,8 @@ public void MsBuildForwardAllPropertiesFromChildLaunchChildNode()
655655 _logger . AssertLogContains ( "[success]" ) ;
656656 Assert . Single ( _logger . ProjectStartedEvents ) ;
657657
658- ProjectStartedEventArgs projectStartedEvent = _logger . ProjectStartedEvents [ 0 ] ;
659- Dictionary < string , string > properties = ExtractProjectStartedPropertyList ( projectStartedEvent . Properties ) ;
658+ ProjectEvaluationFinishedEventArgs evalFinishedEvent = _logger . EvaluationFinishedEvents [ 0 ] ;
659+ Dictionary < string , string > properties = ExtractProjectStartedPropertyList ( evalFinishedEvent . Properties ) ;
660660
661661 Assert . True ( properties . TryGetValue ( "InitialProperty1" , out string propertyValue ) ) ;
662662 Assert . Equal ( "InitialProperty1" , propertyValue ) ;
@@ -704,7 +704,15 @@ public void OutOfProcNodeForwardCertainproperties()
704704 var data = new BuildRequestData ( project . FullPath , new Dictionary < string , string > ( ) ,
705705 MSBuildDefaultToolsVersion , Array . Empty < string > ( ) , null ) ;
706706
707- BuildResult result = _buildManager . Build ( _parameters , data ) ;
707+ // We need to recreate build parameters to ensure proper capturing of newly set environment variables
708+ BuildParameters parameters = new BuildParameters
709+ {
710+ ShutdownInProcNodeOnBuildFinish = true ,
711+ Loggers = new ILogger [ ] { _logger } ,
712+ EnableNodeReuse = false
713+ } ;
714+
715+ BuildResult result = _buildManager . Build ( parameters , data ) ;
708716 Assert . Equal ( BuildResultCode . Success , result . OverallResult ) ;
709717 _logger . AssertLogContains ( "[success]" ) ;
710718 Assert . Single ( _logger . ProjectStartedEvents ) ;
@@ -760,11 +768,21 @@ public void OutOfProcNodeForwardCertainpropertiesAlsoGetResultsFromCache()
760768 _env . SetEnvironmentVariable ( "MsBuildForwardPropertiesFromChild" , "InitialProperty3;IAMNOTREAL" ) ;
761769 _env . SetEnvironmentVariable ( "MSBUILDNOINPROCNODE" , "1" ) ;
762770
771+ _env . SetEnvironmentVariable ( "MSBUILDLOGPROPERTIESANDITEMSAFTEREVALUATION" , "0" ) ;
772+
763773 var project = CreateProject ( contents , null , _projectCollection , false ) ;
764774 var data = new BuildRequestData ( project . FullPath , new Dictionary < string , string > ( ) ,
765775 MSBuildDefaultToolsVersion , Array . Empty < string > ( ) , null ) ;
766776
767- BuildResult result = _buildManager . Build ( _parameters , data ) ;
777+ // We need to recreate build parameters to ensure proper capturing of newly set environment variables
778+ BuildParameters parameters = new BuildParameters
779+ {
780+ ShutdownInProcNodeOnBuildFinish = true ,
781+ Loggers = new ILogger [ ] { _logger } ,
782+ EnableNodeReuse = false
783+ } ;
784+
785+ BuildResult result = _buildManager . Build ( parameters , data ) ;
768786 Assert . Equal ( BuildResultCode . Success , result . OverallResult ) ;
769787 _logger . AssertLogContains ( "[success]" ) ;
770788 Assert . Equal ( 3 , _logger . ProjectStartedEvents . Count ) ;
@@ -785,7 +803,8 @@ public void OutOfProcNodeForwardCertainpropertiesAlsoGetResultsFromCache()
785803 Assert . Equal ( "InitialProperty3" , propertyValue ) ;
786804
787805 projectStartedEvent = _logger . ProjectStartedEvents [ 2 ] ;
788- Assert . Null ( projectStartedEvent . Properties ) ;
806+ properties = ExtractProjectStartedPropertyList ( projectStartedEvent . Properties ) ;
807+ ( properties == null || properties . Count == 0 ) . ShouldBeTrue ( ) ;
789808 }
790809
791810 /// <summary>
@@ -822,7 +841,7 @@ public void ForwardNoPropertiesLaunchChildNode()
822841
823842 ProjectStartedEventArgs projectStartedEvent = _logger . ProjectStartedEvents [ 0 ] ;
824843 Dictionary < string , string > properties = ExtractProjectStartedPropertyList ( projectStartedEvent . Properties ) ;
825- Assert . Null ( properties ) ;
844+ ( properties == null || properties . Count == 0 ) . ShouldBeTrue ( ) ;
826845 }
827846
828847 /// <summary>
@@ -919,7 +938,7 @@ public void ForwardNoPropertiesLaunchChildNodeDefault()
919938
920939 ProjectStartedEventArgs projectStartedEvent = _logger . ProjectStartedEvents [ 0 ] ;
921940 Dictionary < string , string > properties = ExtractProjectStartedPropertyList ( projectStartedEvent . Properties ) ;
922- Assert . Null ( properties ) ;
941+ ( properties == null || properties . Count == 0 ) . ShouldBeTrue ( ) ;
923942 }
924943
925944 /// <summary>
@@ -3475,9 +3494,11 @@ private static string BuildAndCheckCache(BuildManager localBuildManager, IEnumer
34753494 /// </summary>
34763495 private static Dictionary < string , string > ExtractProjectStartedPropertyList ( IEnumerable properties )
34773496 {
3478- // Gather a sorted list of all the properties.
3479- return properties ? . Cast < DictionaryEntry > ( )
3480- . ToDictionary ( prop => ( string ) prop . Key , prop => ( string ) prop . Value , StringComparer . OrdinalIgnoreCase ) ;
3497+ Dictionary < string , string > propertiesLookup = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase ) ;
3498+ Internal . Utilities . EnumerateProperties ( properties , propertiesLookup ,
3499+ static ( dict , kvp ) => dict . Add ( kvp . Key , kvp . Value ) ) ;
3500+
3501+ return propertiesLookup ;
34813502 }
34823503
34833504 /// <summary>
0 commit comments