CS-Script is a free and open-source scripting platform that enables the creation of scripts in ECMA-compliant C# syntax. These scripts have access to .NET Framework or Mono APIs. It is a CLR (Common Language Runtime) based scripting system and is considered one of the most mature C# scripting solutions.
Overview
CS-Script was first released publicly in 2004, just two years after the initial release of .NET. It was the first comprehensive scripting platform for the .NET ecosystem. The developer is Oleg Shilo, and the project is distributed under the MIT License.
The platform supports both hosted and standalone (CLI) execution models. This allows CS-Script to be used as a pure C# alternative for PowerShell or Bash, as well as for extending .NET applications with C# scripts executed at runtime by the hosted script engine.
Technical Details
CS-Script is compatible with Windows, Linux, and macOS. It currently supports .NET 5/.NET Core and higher, as well as the .NET Framework. The underlying compiling technology can be seamlessly switched between Mono, Roslyn, and CodeDOM compilers without affecting the code base.
Stable release: 3.30.5.2 / 24 December 2020
Platform: .NET Framework (with CS-Script.Core targeting .NET)
Size: 10 MB
Key Features
- Simple deployment: Only the script and engine file (about 100 KB) are needed on a system with .NET runtime installed.
- Portability: Scripts can run on any system with a CLR installed, including Mono.
- Full-featured C#: Supports VB.NET, C++/CLI, and J#. All .NET functionality is available, including FCL, COM Interop, Remoting, WPF, and WCF.
- Optimized interpretation: Any statement in the script is interpreted only once, even if used frequently.
- Strongly typed: Strong typing is enforced, which is uncommon for scripting languages.
- Extensibility: The scripting system can be extended with assemblies written in any .NET language or COM components.
- Script hosting: Can be run within Windows Script Host (WSH) and can be mixed in one WSF file.
Development Tools Integration
CS-Script offers integration with several development environments and tools:
- Visual Studio (via the
-vsCLI argument) - Visual Studio Code (via a dedicated extension)
- Sublime Text 3 (via a plugin)
- Notepad++ (via a plugin)
- Command Prompt, Bash shell, and Windows Explorer
FlashDevelop uses CS-Script as its internal scripting engine.
Usage Examples
CS-Script can execute C# scripts directly from the command line without building an executable assembly. For example, a script file (mp4_retag.cs) that updates media file tags can be executed with:
C:\Temp>cscs mp4_retag.cs
Scripts can also be loaded and executed from within .NET host applications using the CSScript API, allowing runtime code execution with access to the full .NET Framework or .NET Core class libraries.
Repository and Website
- Official website: www.cs-script.net
- Source code repository: github.com/oleg-shilo/cs-script
- NuGet package: Available as "CS-Script" on NuGet Gallery