Skip to content

Add limited support for binarylogger to MSBuildWorkspace#80120

Merged
JoeRobich merged 14 commits intomainfrom
dev/jorobich/binary-logger
Oct 14, 2025
Merged

Add limited support for binarylogger to MSBuildWorkspace#80120
JoeRobich merged 14 commits intomainfrom
dev/jorobich/binary-logger

Conversation

@JoeRobich
Copy link
Member

@JoeRobich JoeRobich commented Sep 3, 2025

With the move to using a separate BuildHost we lost binlog support in MSBuildWorkspace. The issue being that we need to serialize arbitrary MSBuild ILogger implementations to send OOP. This change checks if the logger is a BinaryLogger and sends it across using a BinLogPathProvider.

fixes #72202

With the move to using a separate BuildHost we lost binlog support in MSBuildWorkspace. The issue being serializing arbitrary MSBuild ILogger implementations to send OOP. This change check the logger's type and if it is BinaryLogger we send it across using a BinLogPathProvider.
@Youssef1313
Copy link
Member

Does this fix #72202?

return logger?.GetType().FullName == "Microsoft.Build.Logging.BinaryLogger";
}

private sealed class DefaultBinLogPathProvider(string? logFilePath) : IBinLogPathProvider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't there other parameters we also need to deal with for the BinaryLogger that might end up here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the BinaryLogger docs

The only supported parameter is the output log file path (for example, "msbuild.binlog").

@RikkiGibson
Copy link
Member

One of our partners hit a scenario where this option would help diagnose an unexpected behavior with dotnet format.

Co-authored-by: Rikki Gibson <rigibson@microsoft.com>
@jasonmalinowski jasonmalinowski self-requested a review October 9, 2025 17:35
return logger?.GetType().FullName == "Microsoft.Build.Logging.BinaryLogger";
}

internal sealed class DefaultBinLogPathProvider : IBinLogPathProvider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit it's not entirely clear to me what the "Default" is doing in this type name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, having an interface and a default impl seems like overkill here.

See if this feature might be helpful:
https://github.com/dotnet/msbuild/pull/11910/files

The optional LogFile specifies the path where the binary log is saved. To generate a distinct log file for each build, the token "{}" can be added into the path, for example: LogFile=output-{}-log.binlog. Each "{}" in the log path is replaced with a unique string using the timestamp, running process Id and random string stamp.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @KirillOsenkov!

Comment on lines +51 to +65
var newLogPaths = Enumerable.Range(0, 10)
.Select(_ => provider.GetNewLogPath())
.ToImmutableHashSet();
Assert.Equal(10, newLogPaths.Count);

foreach (var newLogPath in newLogPaths)
{
var newLogDirectory = Path.GetDirectoryName(newLogPath);
var newLogFileName = Path.GetFileNameWithoutExtension(newLogPath);
var newLogExtension = Path.GetExtension(newLogPath);

Assert.Equal(LogDirectory, newLogDirectory);
Assert.StartsWith(LogFileName, newLogFileName);
Assert.Equal(DefaultExtension, newLogExtension);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these all the same asserts? Can we switch this to just be a theory with the different inputs of the file name?


var buildHostProcessManager = new BuildHostProcessManager(Properties, loggerFactory: _loggerFactory);
var binLogPathProvider = IsBinaryLogger(msbuildLogger)
? new DefaultBinLogPathProvider(msbuildLogger.Parameters!)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note it's possible for the parameters to contain more than just the file path:

https://github.com/dotnet/msbuild/blob/8a29b764c2d97b678afda0a17705ccc238d58ad6/src/Build/Logging/BinaryLogger/BinaryLogger.cs#L427

I'm almost tempted to say we should just reflect on the logger, and if it has a FilePath property just use it, and fall back to using the Parameters property if it's not present. (FYI to @KirillOsenkov)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only supported parameter is the output log file path (for example, "msbuild.binlog")

The word "supported" is doing a lot of work. (see doc)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the doc just needs to be updated. Seems safe to just set the FilePath, if you don't set it at all it will default to msbuild.binlog. There's a feature where if you include {} in the file path it will generate a unique name for the binlog.

Co-authored-by: Jason Malinowski <jason.malinowski@microsoft.com>
@JoeRobich JoeRobich enabled auto-merge (squash) October 14, 2025 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenProjectAsync logger's parameter is unused (public API)

7 participants