Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
scriptcs supports REPL which is an acronym for
Read–Eval–Print Loop. The scriptcs REPL allows you to quickly try out and experiment with C# code without the need of a script file or IDE.
The REPL uses the context of the directory it's executed in, so you automatically have access to all installed packages.
The scriptcs REPL can be started by running scriptcs without any parameters.
To exit, press
CTRL+C at any time.
Referencing assemblies from REPL
To reference other assemblies, you can use the #r directive.
C:\>scriptcs scriptcs (ctrl-c to exit or :help for help) > #r "MyAssembly.dll"
The scriptcs runtime will first try to resolve and load the assembly from the bin folder, and if that fails, try loading it from the GAC.
Referencing script files from REPL
To reference other script files, you can use the #load directive. The path provided can be either absolute or relative.
C:\>scriptcs scriptcs (ctrl-c to exit or :help for help) > #load "MyFile.csx" > #load "C:/MyFile.csx"
Referencing NuGet packages from REPL
In the example below, we install the Newtonsoft.Json NuGet package and use it inside the scriptcs REPL.
C:\>scriptcs -install Newtonsoft.Json INFO : Installing packages... Installing packages... Installed: Newtonsoft.Json Package installation succeeded. Saving packages in scriptcs_packages.config... Creating scriptcs_packages.config... Added Newtonsoft.Json (v6.0.8, .NET 4.5) to scriptcs_packages.config Successfully updated scriptcs_packages.config. C:\>scriptcs scriptcs (ctrl-c to exit or :help for help) > using Newtonsoft.Json; > JsonConvert.SerializeObject(DateTime.Now); "2013-05-22T12:50:47.2474102+02:00"