@@ -72,15 +72,30 @@ private static string EvaluateCIProperty(Dictionary<string, string> overrides)
7272 foreach ( var ( key , value ) in overrides )
7373 globalProperties [ key ] = value ;
7474
75- using var collection = new ProjectCollection ( globalProperties ) ;
76- string xml = $ """
77- <Project>
78- <Import Project="{ TargetsPath . Replace ( @"\" , "/" ) } " />
79- </Project>
80- """ ;
81- using var reader = XmlReader . Create ( new StringReader ( xml ) ) ;
82- ProjectRootElement rootElement = ProjectRootElement . Create ( reader , collection ) ;
83- var project = new Project ( rootElement , null , null , collection ) ;
84- return project . GetPropertyValue ( "CI" ) ;
75+ // CI itself is not in _ciVarNames (it's the output property, not an input condition
76+ // variable), but GitHub Actions sets CI=true in the OS environment. If it leaks in,
77+ // the outer <PropertyGroup Condition="'$(CI)' == ''"> guard short-circuits and the
78+ // entire detection block is skipped. Temporarily remove it from the process environment
79+ // so MSBuild doesn't see it, unless the caller is explicitly testing the CI=true case.
80+ string ? savedCI = Environment . GetEnvironmentVariable ( "CI" ) ;
81+ if ( ! overrides . ContainsKey ( "CI" ) )
82+ Environment . SetEnvironmentVariable ( "CI" , null ) ;
83+ try
84+ {
85+ using var collection = new ProjectCollection ( globalProperties ) ;
86+ string xml = $ """
87+ <Project>
88+ <Import Project="{ TargetsPath . Replace ( @"\" , "/" ) } " />
89+ </Project>
90+ """ ;
91+ using var reader = XmlReader . Create ( new StringReader ( xml ) ) ;
92+ ProjectRootElement rootElement = ProjectRootElement . Create ( reader , collection ) ;
93+ var project = new Project ( rootElement , null , null , collection ) ;
94+ return project . GetPropertyValue ( "CI" ) ;
95+ }
96+ finally
97+ {
98+ Environment . SetEnvironmentVariable ( "CI" , savedCI ) ;
99+ }
85100 }
86101}
0 commit comments