FractalDataWorks.Workspace.Roslyn
0.4.0-preview.6
dotnet add package FractalDataWorks.Workspace.Roslyn --version 0.4.0-preview.6
NuGet\Install-Package FractalDataWorks.Workspace.Roslyn -Version 0.4.0-preview.6
<PackageReference Include="FractalDataWorks.Workspace.Roslyn" Version="0.4.0-preview.6" />
<PackageVersion Include="FractalDataWorks.Workspace.Roslyn" Version="0.4.0-preview.6" />
<PackageReference Include="FractalDataWorks.Workspace.Roslyn" />
paket add FractalDataWorks.Workspace.Roslyn --version 0.4.0-preview.6
#r "nuget: FractalDataWorks.Workspace.Roslyn, 0.4.0-preview.6"
#:package FractalDataWorks.Workspace.Roslyn@0.4.0-preview.6
#addin nuget:?package=FractalDataWorks.Workspace.Roslyn&version=0.4.0-preview.6&prerelease
#tool nuget:?package=FractalDataWorks.Workspace.Roslyn&version=0.4.0-preview.6&prerelease
FractalDataWorks.Workspace.Roslyn
Roslyn workspace management with snapshot/rollback capabilities.
Overview
This package provides a managed Roslyn workspace that tracks solution state with the ability to snapshot and rollback changes. It serves as the foundation for all FractalDataWorks development tools.
Key Types
IRoslynWorkspace- Interface for Roslyn workspace operations with project filteringIWorkspace<T>- Generic workspace interface with snapshot/rollbackRoslynWorkspace- Implementation managing Solution stateRoslynWorkspaceFactory- Factory for creating workspaces from solution filesWorkspaceSnapshot- Captured workspace state for rollbackProjectInfo- Information about projects in a solutionDefaultExcludePatterns- Common patterns for excluding test projects
Usage
Loading a Solution
From RoslynWorkspaceFactory.cs:45-49:
public Task<IRoslynWorkspace> CreateFromSolution(
string solutionPath,
CancellationToken cancellationToken = default)
{
return CreateFromSolution(solutionPath, [], cancellationToken);
Example usage:
var factory = new RoslynWorkspaceFactory();
var workspace = await factory.CreateFromSolution("/path/to/solution.sln");
// Access current solution
var solution = workspace.CurrentSolution;
var projects = solution.Projects;
Loading with Project Filtering
From IRoslynWorkspaceFactory.cs:22-36:
Task<IRoslynWorkspace> CreateFromSolution(
string solutionPath,
IReadOnlyList<string> excludePatterns,
CancellationToken cancellationToken = default);
Example usage with test project exclusion:
var factory = new RoslynWorkspaceFactory();
var workspace = await factory.CreateFromSolution(
"/path/to/solution.sln",
DefaultExcludePatterns.TestProjects);
Making Changes
From IRoslynWorkspace.cs:39-47:
// CORRECT - capture and update
var newSolution = workspace.CurrentSolution.AddDocument(...);
workspace.UpdateSolution(newSolution);
// WRONG - loses changes!
workspace.CurrentSolution.AddDocument(...);
Snapshot and Rollback
From IWorkspace.cs:45-57:
string CreateSnapshot(string name, string description);
IGenericResult<T> RestoreSnapshot(string snapshotId);
Example usage:
// Take snapshot before risky operations
var snapshotId = workspace.CreateSnapshot("before-refactor", "State before rename refactoring");
try
{
// Make changes...
workspace.UpdateSolution(modifiedSolution);
// Verify changes compile
var diagnostics = await GetDiagnosticsAsync();
if (diagnostics.Any(d => d.Severity == DiagnosticSeverity.Error))
{
// Rollback on failure
var result = workspace.RestoreSnapshot(snapshotId);
if (!result.IsSuccess)
{
// Handle restore failure
}
}
}
catch
{
workspace.RestoreSnapshot(snapshotId);
throw;
}
Setting Baseline for Diff
From IWorkspace.cs:38-42:
void SetBaseline(T state);
From IRoslynWorkspace.cs:52-62:
IReadOnlyDictionary<string, string> GetChangesFromBaseline();
Example usage:
// Set baseline before editing session (captures current state)
workspace.SetBaseline(workspace.CurrentSolution);
// Make multiple changes...
// Get all changes since baseline (returns file path -> content dictionary)
var changes = workspace.GetChangesFromBaseline();
foreach (var (filePath, content) in changes)
{
Console.WriteLine($"Changed: {filePath}");
}
Managing Projects
From IRoslynWorkspace.cs:89-103:
IReadOnlyList<ProjectInfo> GetAllProjects();
IReadOnlyList<ProjectInfo> GetLoadedProjects();
IReadOnlyList<ProjectInfo> GetExcludedProjects();
Example usage:
// List excluded projects
var excluded = workspace.GetExcludedProjects();
foreach (var project in excluded)
{
Console.WriteLine($"{project.Name} excluded by: {project.ExcludedByPattern}");
}
// Load an excluded project on demand
var result = await workspace.LoadProject("MyProject.Tests");
if (result.IsSuccess)
{
Console.WriteLine($"Loaded: {result.Value.Name}");
}
Thread Safety
The workspace uses immutable Solution objects. While the Solution itself is thread-safe, workspace operations (Update, Snapshot, Restore) should be synchronized if accessed from multiple threads.
Dependencies
Microsoft.CodeAnalysis.Workspaces- Roslyn workspace infrastructureMicrosoft.CodeAnalysis.CSharp- C# language supportMicrosoft.Build.Locator- MSBuild SDK locationFractalDataWorks.Results- Result types for operation outcomes
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- FractalDataWorks.Collections (>= 0.4.0-preview.6)
- FractalDataWorks.MessageLogging.Abstractions (>= 0.4.0-preview.6)
- FractalDataWorks.Messages (>= 0.4.0-preview.6)
- FractalDataWorks.Results (>= 0.4.0-preview.6)
- FractalDataWorks.Results.Abstractions (>= 0.4.0-preview.6)
- Microsoft.Build.Locator (>= 1.11.2)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 5.0.0)
- Microsoft.CodeAnalysis.Workspaces.MSBuild (>= 5.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.1)
NuGet packages (11)
Showing the top 5 NuGet packages that depend on FractalDataWorks.Workspace.Roslyn:
| Package | Downloads |
|---|---|
|
CyberdyneDevelopment.DeveloperTools.Analysis
Development tools and utilities for the FractalDataWorks ecosystem. Build: |
|
|
CyberdyneDevelopment.DeveloperTools.Compilation
Development tools and utilities for the FractalDataWorks ecosystem. Build: |
|
|
CyberdyneDevelopment.DeveloperTools.Formatting
Development tools and utilities for the FractalDataWorks ecosystem. Build: |
|
|
CyberdyneDevelopment.DeveloperTools.Navigation
Development tools and utilities for the FractalDataWorks ecosystem. Build: |
|
|
CyberdyneDevelopment.DeveloperTools.Generation
Development tools and utilities for the FractalDataWorks ecosystem. Build: |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|