FractalDataWorks.Workspace.Roslyn 0.4.0-preview.6

This is a prerelease version of FractalDataWorks.Workspace.Roslyn.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package FractalDataWorks.Workspace.Roslyn --version 0.4.0-preview.6
                    
NuGet\Install-Package FractalDataWorks.Workspace.Roslyn -Version 0.4.0-preview.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FractalDataWorks.Workspace.Roslyn" Version="0.4.0-preview.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FractalDataWorks.Workspace.Roslyn" Version="0.4.0-preview.6" />
                    
Directory.Packages.props
<PackageReference Include="FractalDataWorks.Workspace.Roslyn" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FractalDataWorks.Workspace.Roslyn --version 0.4.0-preview.6
                    
#r "nuget: FractalDataWorks.Workspace.Roslyn, 0.4.0-preview.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FractalDataWorks.Workspace.Roslyn@0.4.0-preview.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FractalDataWorks.Workspace.Roslyn&version=0.4.0-preview.6&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=FractalDataWorks.Workspace.Roslyn&version=0.4.0-preview.6&prerelease
                    
Install as a Cake Tool

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 filtering
  • IWorkspace<T> - Generic workspace interface with snapshot/rollback
  • RoslynWorkspace - Implementation managing Solution state
  • RoslynWorkspaceFactory - Factory for creating workspaces from solution files
  • WorkspaceSnapshot - Captured workspace state for rollback
  • ProjectInfo - Information about projects in a solution
  • DefaultExcludePatterns - 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 infrastructure
  • Microsoft.CodeAnalysis.CSharp - C# language support
  • Microsoft.Build.Locator - MSBuild SDK location
  • FractalDataWorks.Results - Result types for operation outcomes
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed