Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/MSBuild.UnitTests/XMake_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,44 @@ public void TestProcessFileLoggerSwitch5()
distributedLoggerRecords.Count.ShouldBe(0); // "Expected no distributed loggers to be attached"
loggers.Count.ShouldBe(0); // "Expected no central loggers to be attached"
}

/// <summary>
/// Verify that DistributedLoggerRecords with null CentralLogger don't cause exceptions when creating ProjectCollection
/// This is a regression test for the issue where -dfl flag caused MSB1025 error due to null logger not being filtered.
/// </summary>
[Fact]
public void TestNullCentralLoggerInDistributedLoggerRecord()
{
// Simulate the scenario when using -dfl flag
// ProcessDistributedFileLogger creates a DistributedLoggerRecord with null CentralLogger
var distributedLoggerRecords = new List<DistributedLoggerRecord>();
bool distributedFileLogger = true;
string[] fileLoggerParameters = null;

MSBuildApp.ProcessDistributedFileLogger(
distributedFileLogger,
fileLoggerParameters,
distributedLoggerRecords);

// Verify that we have a distributed logger record with null central logger
distributedLoggerRecords.Count.ShouldBe(1);
distributedLoggerRecords[0].CentralLogger.ShouldBeNull();

// This should not throw ArgumentNullException when creating ProjectCollection
// The fix filters out null central loggers from the evaluationLoggers array
var loggers = Array.Empty<ILogger>();
Should.NotThrow(() =>
{
using var projectCollection = new ProjectCollection(
new Dictionary<string, string>(),
loggers: [.. loggers, .. distributedLoggerRecords.Select(d => d.CentralLogger).Where(l => l is not null)],
remoteLoggers: null,
toolsetDefinitionLocations: ToolsetDefinitionLocations.Default,
maxNodeCount: 1,
onlyLogCriticalEvents: false,
loadProjectsReadOnly: true);
});
}
#endregion

#region ProcessConsoleLoggerSwitches
Expand Down
4 changes: 2 additions & 2 deletions src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,8 +1392,8 @@ internal static bool BuildProject(
// all of the loggers that are single-node only
.. loggers,
// all of the central loggers for multi-node systems. These need to be resilient to multiple calls
// to Initialize
.. distributedLoggerRecords.Select(d => d.CentralLogger)
// to Initialize. Filter out null loggers (e.g., DistributedFileLogger uses null central logger).
.. distributedLoggerRecords.Select(d => d.CentralLogger).Where(l => l is not null)
];

projectCollection = new ProjectCollection(
Expand Down