CDS.CSharpScript2 2.4.1

dotnet add package CDS.CSharpScript2 --version 2.4.1
                    
NuGet\Install-Package CDS.CSharpScript2 -Version 2.4.1
                    
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="CDS.CSharpScript2" Version="2.4.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CDS.CSharpScript2" Version="2.4.1" />
                    
Directory.Packages.props
<PackageReference Include="CDS.CSharpScript2" />
                    
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 CDS.CSharpScript2 --version 2.4.1
                    
#r "nuget: CDS.CSharpScript2, 2.4.1"
                    
#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 CDS.CSharpScript2@2.4.1
                    
#: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=CDS.CSharpScript2&version=2.4.1
                    
Install as a Cake Addin
#tool nuget:?package=CDS.CSharpScript2&version=2.4.1
                    
Install as a Cake Tool

CDS.CSharpScript2

Roslyn-powered C# scripting engine for .NET 10.

Description

CDS.CSharpScript2 lets you embed full C# scripting — compilation, execution, IntelliSense, and syntax classification — into any .NET 10 application.

Features

  • Compile & execute C# scripts with Roslyn, with support for globals (host-supplied state).
  • IntelliSense — code completion, symbol classification, and signature help (call tips).
  • Diagnostics — surface compiler errors and warnings back to your UI.
  • Assembly references — reference any managed assembly, including third-party NuGet packages.
  • Immutable configuration — compose ScriptEnvironment instances fluently; safe to cache and share.

Quick Start

Simple execution

using CDS.CSharpScript2;

using var context = await ScriptContext.CreateAsync();
var ctx = context.ApplyScript("1 + 1");

var executable = await new ScriptExecutor(ctx).CompileAsync<int>();
int result = await executable.RunAsync<int>(); // 2

With global variables

public class MyGlobals
{
    public double X { get; set; }
    public double Y { get; set; }
}

var env = ScriptEnvironment.Default.WithGlobalType<MyGlobals>();

using var context = await ScriptContext.CreateAsync(env);
var ctx = context.ApplyScript("X * Y");

var executable = await new ScriptExecutor(ctx).CompileAsync<double>();
double result = await executable.RunAsync<double>(new MyGlobals { X = 3, Y = 4 }); // 12.0

With additional namespaces and references

var env = ScriptEnvironment.Default
    .WithAdditionalNamespaceForType<System.Text.StringBuilder>()
    .WithAdditionalReferenceForType<MathNet.Numerics.Constants>();

using var context = await ScriptContext.CreateAsync(env);

Key Types

Type Purpose
ScriptEnvironment Immutable configuration: namespace imports, assembly references, globals type
ScriptContext Roslyn workspace document paired with an environment; disposable
ScriptExecutor Compiles a ScriptContext into an ExecutableScript
ExecutableScript Compiled script ready to run; reports diagnostics and accepts a globals object

Editor Integration

Pair with the editor package for a ready-to-use WinForms control:

Requirements

  • .NET 10.0

Attributions

Icon by Flaticon Uicons

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. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CDS.CSharpScript2:

Package Downloads
CDS.CSharpScript2.ScintillaEditor

Scintilla5-based WinForms editor control for embedding C# script editing in .NET 10 Windows applications. Provides syntax highlighting, IntelliSense, code completion, call tips, and hover info — all powered by Roslyn.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.4.1 50 7/1/2026
2.3.1-alpha.0.5 40 7/1/2026