Add ability to create a compiler log from a Roslyn workspace#340
Conversation
Co-authored-by: jaredpar <[email protected]>
|
@jaredpar any plans for this one out of interest? |
|
@slang25 just been working on other things that got my attention. Is there a particular situation that you wanted this for? |
|
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 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. |
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.complogfor later investigation.New public API
Usage:
Implementation
CompilerLogBuilder.AddFromWorkspace(Project, CancellationToken)— new internal method that serializes a workspaceProject:PortableExecutableReferencewith aFilePath→ reads assembly from disk (same as binlog path)CompilationReference(project-to-project) → emits the referenced compilation to memory and embeds the PE bytesAnalyzerFileReference→ reads from disk; other analyzer reference types produce a diagnostic and are skippedCompilerLogUtil.CreateFromWorkspace— iteratesworkspace.CurrentSolution.Projects, callsAddFromWorkspaceper project, returns collected diagnosticsLimitations
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. UseBasicAnalyzerKind.OnDiskorBasicAnalyzerKind.Noneto 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.