@@ -211,7 +211,7 @@ public override int Execute()
211211 }
212212
213213 // Set up MSBuild.
214- ReadOnlySpan < ILogger > binaryLoggers = binaryLogger is null ? [ ] : [ binaryLogger ] ;
214+ ReadOnlySpan < ILogger > binaryLoggers = binaryLogger is null ? [ ] : [ binaryLogger . Value ] ;
215215 IEnumerable < ILogger > loggers = [ .. binaryLoggers , consoleLogger ] ;
216216 var projectCollection = new ProjectCollection (
217217 MSBuildArgs . GlobalProperties ,
@@ -276,7 +276,7 @@ public override int Execute()
276276 Environment . SetEnvironmentVariable ( key , value ) ;
277277 }
278278
279- binaryLogger ? . ReallyShutdown ( ) ;
279+ binaryLogger ? . Value . ReallyShutdown ( ) ;
280280 consoleLogger . Shutdown ( ) ;
281281 }
282282
@@ -304,7 +304,7 @@ static Action<IDictionary<string, string>> AddRestoreGlobalProperties(ReadOnlyDi
304304 } ;
305305 }
306306
307- static FacadeLogger ? GetBinaryLogger ( IReadOnlyList < string > ? args )
307+ static Lazy < FacadeLogger > ? GetBinaryLogger ( IReadOnlyList < string > ? args )
308308 {
309309 if ( args is null ) return null ;
310310 // Like in MSBuild, only the last binary logger is used.
@@ -313,13 +313,17 @@ static Action<IDictionary<string, string>> AddRestoreGlobalProperties(ReadOnlyDi
313313 var arg = args [ i ] ;
314314 if ( LoggerUtility . IsBinLogArgument ( arg ) )
315315 {
316- var logger = new BinaryLogger
316+ // We don't want to create the binlog file until actually needed, hence we wrap this in a Lazy.
317+ return new ( ( ) =>
317318 {
318- Parameters = arg . IndexOf ( ':' ) is >= 0 and var index
319- ? arg [ ( index + 1 ) ..]
320- : "msbuild.binlog" ,
321- } ;
322- return LoggerUtility . CreateFacadeLogger ( [ logger ] ) ;
319+ var logger = new BinaryLogger
320+ {
321+ Parameters = arg . IndexOf ( ':' ) is >= 0 and var index
322+ ? arg [ ( index + 1 ) ..]
323+ : "msbuild.binlog" ,
324+ } ;
325+ return LoggerUtility . CreateFacadeLogger ( [ logger ] ) ;
326+ } ) ;
323327 }
324328 }
325329
0 commit comments