| 1 | using Microsoft.CodeAnalysis; |
| 2 | using Microsoft.CodeAnalysis.MSBuild; |
| 3 | |
| 4 | namespace RoslynMcp.ServiceLayer; |
| 5 | |
| 6 | internal static class WorkspaceOpen |
| 7 | { |
| 8 | public static async Task<Solution?> OpenSolutionOrProjectAsync( |
| 9 | MSBuildWorkspace workspace, |
| 10 | string solutionOrProjectPath, |
| 11 | CancellationToken cancellationToken) |
| 12 | { |
| 13 | if (string.Equals(Path.GetExtension(solutionOrProjectPath), ".sln", StringComparison.OrdinalIgnoreCase)) |
| 14 | return await workspace.OpenSolutionAsync(solutionOrProjectPath, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 15 | |
| 16 | var project = await workspace.OpenProjectAsync(solutionOrProjectPath, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 17 | return project.Solution; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | |
View only · write via MCP/CIDE