• Stars
    star
    1,620
  • Rank 28,882 (Top 0.6 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 29 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C# scripting platform

stand with Ukraine

CS-Script


This page is a one-minute-read info about the brightest features of the system. The complete overview can be found on Wiki


Please note that this repository is hosting the releases of CS-Script (v4.0.0 and higher). Previous content of this repository and wiki (.NET Framework edition of CS-Script) has been been moved to the new repository: https://github.com/oleg-shilo/cs-script.net-framework

Note .NET SDK is required to have all features. However the core features can utilized even with .NET Runtime only. See details.


Build status Chocolatey Version Chocolatey Downloads NuGet version (CS-Script)

paypal

CS-Script is a CLR based scripting system which uses ECMA-compliant C# as a programming language.

CS-Script is one of the most mature C# scripting solutions. It became publicly available in 2004, just two years after the first release of .NET. And it was the first comprehensive scripting platform for .NET

CS-Script supports both hosted and standalone (CLI) execution model. This makes it possible to use the script engine as a pure C# alternative for PowerShell. As well as extending .NET applications with C# scripts executed at runtime by the hosted script engine.

CS-Script allows seamlessly switching underlying compiling technology without affecting the code base. Currently supported compilers are dotnet.exe and csc.exe.

CS-Script also offers comprehensive integration with most common development tools:

It can be run on Win and Linux. Class library for hosting the script engine is compiled for ".NET Standard" so it can be hosted by any managed application.

Over the long history of CS-Script it has been downloaded through Notepad++ x86 plugin manager alone over times (stats till July 2017).


Documentation disclaimer Please be aware that currently the online Documentation Wiki is being reviewed and updated. This is review/rework hs been triggered by the convergence of two CS-Script development and distribution streams for .NET Core and .NET Framework.Meaning that until this review is completed and this disclaimer is removed some of the Wiki content may not be fully accurate.

The most accurate and concise documentation is embedded in the engine executable and can be accessed via CLI "help" command:

css -help

A copy of the help content can be accessed here


The following section describes a few use cases just to give you the idea about the product:

CLI: Executing script from shell

CS-Script follows many elements of the Python user experience model. Thus a script can reference other scripts, .NET assemblies or even NuGet packages. It also uses Python style caching ensuring that script that was executed at least once is never compiled again unless the script code is changes. This ensures ultimate performance. Thus script execution speed of the consecutive runs matches the excution of fully compiled .NET applications.

Create a simple console script: You can script any type of application that .NET supports (e.g. WinForm, WPF, WEB API) and in two supported syntaxes: C# and VB.

cscs -new script.cs

This creates a sample script file with a sample code. Of course you can also create the script file by yourself. This is a top-level class script:

using System;

Console.WriteLine(user());

string user()
    => Environment.UserName;

Execute script file directly in cmd-prompt/linux-shell without building an executable assembly:

css .\script.cs

Note, while the script engine CLI executables is cscs.exe (on Win) and cscs (on Linux) you can use css shim that is available in both win and linux distro.

CLI: Executing script from IDE

While various IDEs can be used VSCode is arguably the simplest one. You can either load the existing script into it with css -vscode .\script.cs or create a new script within the IDE if you install the CS-Script extension:

Hosting script engine

You can host the script engine in any .NET application. The class library is distributed as a NuGet package CS-Script.

Install-Package CS-Script

The library is built against .NET Standard 2.0 so it can be hosted on any edition of runtime. However the script evaluation is done via .NET 5 tool chain so it needs to be installed on the host PC even if the application is implemented with the older framework (e.g. .NET Framework).

These are just a few samples: The complete content of samples can be found here.

public interface ICalc
{
    int Sum(int a, int b);
}
...
// you can but don't have to inherit your script class from ICalc
ICalc calc = CSScript.Evaluator
                     .LoadCode<ICalc>(@"using System;
                                        public class Script
                                        {
                                            public int Sum(int a, int b)
                                            {
                                                return a+b;
                                            }
                                        }");
int result = calc.Sum(1, 2);
dynamic script = CSScript.Evaluator
                         .LoadMethod(@"int Product(int a, int b)
                                       {
                                           return a * b;
                                       }");

int result = script.Product(3, 2);
public interface ICalc
{
    int Sum(int a, int b);
    int Div(int a, int b);
}
...
ICalc script = CSScript.Evaluator
                       .LoadMethod<ICalc>(@"public int Sum(int a, int b)
                                            {
                                                return a + b;
                                            }
                                            public int Div(int a, int b)
                                            {
                                                return a/b;
                                            }");
int result = script.Div(15, 3);
var log = CSScript.Evaluator
                  .CreateDelegate(@"void Log(string message)
                                    {
                                        Console.WriteLine(message);
                                    }");

log("Test message");

More Repositories

1

wixsharp

Framework for building a complete MSI or WiX source code by using script files written with C# syntax.
C#
1,110
star
2

cs-script.npp

CS-Script (C# Intellisense) plugin for Notepad++ (x86/x64)
C#
247
star
3

shell-x

Dynamic context menu manager for Windows.
C#
144
star
4

cs-script.core

.NET Core port of CS-Script
C#
100
star
5

codemap.vscode

Code map (syntax tree) of the active document
TypeScript
85
star
6

sublime-codemap

CodeMap - is a ST3 plugin for showing the code tree representing the code structure of the active view/document
Python
41
star
7

cs-script.vscode

VSCode extension for CS-Script
TypeScript
40
star
8

cs-script.net-framework

A mirror of the oleg-shilo/cs-script repository of CS-Script for .NET Framework. A copy of the repo before the product migration on .NET 5migrat
C#
30
star
9

Favorites.vscode

VSCode extension for managing Favorites
TypeScript
23
star
10

PyMap.VSIX

CodeMap extension for Visual Studio 2017-2022
C#
18
star
11

CodeMaidPlus

A simple extension that attempts to address some shortcomings of rather excellent CodeMaid.
C#
16
star
12

DocPreview.VSIX

C#
14
star
13

scripts.npp

C#
13
star
14

sublime-favorites

Favorites list for Sublime Text 3
Python
13
star
15

MoveTypeToFile.VSIX

"Move Type To File" Visual Studio 2017/2019 extension
HTML
10
star
16

multiclip

MultiClip
C#
10
star
17

Retired-VSIX

Repository of legacy Visual Studio extensions
10
star
18

cs-script-sublime

Sublime Text 3 plugin for CS-Script
Python
9
star
19

win-sudo

C#
8
star
20

GC-Menu

C#
7
star
21

LineMan.VSIX

Line manipulation extension for Visual Studio 2017
C#
6
star
22

CS-Script.VSIX

C#
5
star
23

StartApp

Instant launcher for heavy UI applications
C#
3
star
24

PropMan.VSIX

Property Manipulation Utilities for encapsulating fields, converting auto-properties to full properties and back.
C#
3
star
25

syntaxer.core

C#
3
star
26

mkshim

C#
3
star
27

syntaxer

C#
2
star
28

TailRecursion

C#
1
star
29

cs-script.sublime.dev

Python
1
star
30

CodeSnippets

C#
1
star
31

Stack-Analyser

A playground for dealing with call stack and assembly metadata
C#
1
star
32

ruta

C#
1
star
33

vscode-issue-reporting

TypeScript
1
star
34

CopyRefs.VSIX

C#
1
star
35

AsyncIt

C# code-generator analyzer for building Async/Sync API
C#
1
star