Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add ability to create a compiler log from a Roslyn workspace#340

Draft
jaredpar with Copilot wants to merge 2 commits into
mainfrom
copilot/add-compiler-log-from-workspace
Draft

Add ability to create a compiler log from a Roslyn workspace#340
jaredpar with Copilot wants to merge 2 commits into
mainfrom
copilot/add-compiler-log-from-workspace

Conversation

Copilot AI commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Until now, compiler logs could only be created from MSBuild binary logs (.binlog). This adds a path to serialize an active Roslyn workspace into a .complog for later investigation.

New public API

// CompilerLogUtil
public static List<string> CreateFromWorkspace(
    Workspace workspace,
    string compilerLogFilePath,
    Func<Project, bool>? predicate = null,
    CancellationToken cancellationToken = default)

public static List<string> CreateFromWorkspace(
    Workspace workspace,
    Stream compilerLogStream,
    Func<Project, bool>? predicate = null,
    CancellationToken cancellationToken = default)

Usage:

using var solutionReader = SolutionReader.Create("build.complog");
var workspace = new AdhocWorkspace();
workspace.AddSolution(solutionReader.ReadSolutionInfo());

// Snapshot the current workspace state
var diagnostics = CompilerLogUtil.CreateFromWorkspace(workspace, "snapshot.complog");

Implementation

  • CompilerLogBuilder.AddFromWorkspace(Project, CancellationToken) — new internal method that serializes a workspace Project:
    • Source, additional, and analyzer-config documents are written preserving original encoding
    • PortableExecutableReference with a FilePath → reads assembly from disk (same as binlog path)
    • CompilationReference (project-to-project) → emits the referenced compilation to memory and embeds the PE bytes
    • AnalyzerFileReference → reads from disk; other analyzer reference types produce a diagnostic and are skipped
  • CompilerLogUtil.CreateFromWorkspace — iterates workspace.CurrentSolution.Projects, calls AddFromWorkspace per project, returns collected diagnostics

Limitations

When a workspace is loaded with BasicAnalyzerKind.InMemory (default on .NET), the in-memory analyzer references cannot be re-serialized as file references and generate skip diagnostics. Use BasicAnalyzerKind.OnDisk or BasicAnalyzerKind.None to avoid this.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI changed the title [WIP] Add ability to create a compiler log from a workspace Add ability to create a compiler log from a Roslyn workspace Mar 17, 2026
Copilot AI requested a review from jaredpar March 17, 2026 00:38
@slang25

slang25 commented May 5, 2026

Copy link
Copy Markdown

@jaredpar any plans for this one out of interest?

@jaredpar

jaredpar commented May 5, 2026

Copy link
Copy Markdown
Owner

@slang25 just been working on other things that got my attention. Is there a particular situation that you wanted this for?

@slang25

slang25 commented May 5, 2026

Copy link
Copy Markdown

Nothing important, but just ran into a situation where I would have reached for this.

I've been using Builldalyzer for years, and have only recently become aware that MSBuildWorkspace has gotten much better to the point that I'm re-evaluating (before 2024 it didn't have an out-of-process model and was super flaky).

I'm working on a large test suite and it would be useful to compare the workspaces that are extracted between the two approaches to see if there are any deficiencies in either library that needs work, so having some form of serialization would allow for a diff-able artifact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to create a compiler log from a workspace

3 participants