@@ -212,29 +212,26 @@ public override int Execute()
212212
213213 // Set up MSBuild.
214214 ReadOnlySpan < ILogger > binaryLoggers = binaryLogger is null ? [ ] : [ binaryLogger ] ;
215+ IEnumerable < ILogger > loggers = [ .. binaryLoggers , consoleLogger ] ;
215216 var projectCollection = new ProjectCollection (
216217 MSBuildArgs . GlobalProperties ,
217- [ .. binaryLoggers , consoleLogger ] ,
218+ loggers ,
218219 ToolsetDefinitionLocations . Default ) ;
219220 var parameters = new BuildParameters ( projectCollection )
220221 {
221- Loggers = projectCollection . Loggers ,
222+ Loggers = loggers ,
222223 LogTaskInputs = binaryLoggers . Length != 0 ,
223224 } ;
224225
225- // Projects need to be created before BeginBuild is called, otherwise binlog doesn't contain evaluation data.
226- var restoreProject = NoRestore ? null : CreateProjectInstance ( projectCollection , addGlobalProperties : AddRestoreGlobalProperties ( MSBuildArgs . RestoreGlobalProperties ) ) ;
227- var buildProject = NoBuild ? null : CreateProjectInstance ( projectCollection ) ;
228-
229226 BuildManager . DefaultBuildManager . BeginBuild ( parameters ) ;
230227
231228 // Do a restore first (equivalent to MSBuild's "implicit restore", i.e., `/restore`).
232229 // See https://github.com/dotnet/msbuild/blob/a1c2e7402ef0abe36bf493e395b04dd2cb1b3540/src/MSBuild/XMake.cs#L1838
233230 // and https://github.com/dotnet/msbuild/issues/11519.
234- if ( restoreProject != null )
231+ if ( ! NoRestore )
235232 {
236233 var restoreRequest = new BuildRequestData (
237- restoreProject ,
234+ CreateProjectInstance ( projectCollection , addGlobalProperties : AddRestoreGlobalProperties ( MSBuildArgs . RestoreGlobalProperties ) ) ,
238235 targetsToBuild : [ "Restore" ] ,
239236 hostServices : null ,
240237 BuildRequestDataFlags . ClearCachesAfterBuild | BuildRequestDataFlags . SkipNonexistentTargets | BuildRequestDataFlags . IgnoreMissingEmptyAndInvalidImports | BuildRequestDataFlags . FailOnUnresolvedSdk ) ;
@@ -247,10 +244,10 @@ public override int Execute()
247244 }
248245
249246 // Then do a build.
250- if ( buildProject != null )
247+ if ( ! NoBuild )
251248 {
252249 var buildRequest = new BuildRequestData (
253- buildProject ,
250+ CreateProjectInstance ( projectCollection ) ,
254251 targetsToBuild : MSBuildArgs . RequestedTargets ?? [ "Build" ] ) ;
255252
256253 var buildResult = BuildManager . DefaultBuildManager . BuildRequest ( buildRequest ) ;
@@ -279,7 +276,7 @@ public override int Execute()
279276 Environment . SetEnvironmentVariable ( key , value ) ;
280277 }
281278
282- binaryLogger ? . Shutdown ( ) ;
279+ binaryLogger ? . ReallyShutdown ( ) ;
283280 consoleLogger . Shutdown ( ) ;
284281 }
285282
@@ -307,7 +304,7 @@ static Action<IDictionary<string, string>> AddRestoreGlobalProperties(ReadOnlyDi
307304 } ;
308305 }
309306
310- static ILogger ? GetBinaryLogger ( IReadOnlyList < string > ? args )
307+ static FacadeLogger ? GetBinaryLogger ( IReadOnlyList < string > ? args )
311308 {
312309 if ( args is null ) return null ;
313310 // Like in MSBuild, only the last binary logger is used.
@@ -316,12 +313,13 @@ static Action<IDictionary<string, string>> AddRestoreGlobalProperties(ReadOnlyDi
316313 var arg = args [ i ] ;
317314 if ( LoggerUtility . IsBinLogArgument ( arg ) )
318315 {
319- return new BinaryLogger
316+ var logger = new BinaryLogger
320317 {
321318 Parameters = arg . IndexOf ( ':' ) is >= 0 and var index
322319 ? arg [ ( index + 1 ) ..]
323320 : "msbuild.binlog" ,
324321 } ;
322+ return LoggerUtility . CreateFacadeLogger ( [ logger ] ) ;
325323 }
326324 }
327325
0 commit comments