Unleash your C# from Visual Studio.

What is it?

scriptcs makes it easy to write and execute C# with a simple text editor.

While Visual Studio, and other IDEs, are powerful tools, they can sometimes hinder productivity more than they promote it. You don’t always need, or want, the overhead of a creating a new solution or project. Sometimes you want to just type away in your favorite text editor.

scriptcs frees you from Visual Studio, without sacrificing the advantages of a strongly-typed language.

Try scriptcs

You can try scriptcs right now in the browser using Kata<oda. Click the image below to get started!

scriptcs_katacoda

Getting scriptcs

Releases and nightly builds should be installed using Chocolatey. Information on installing Chocolatey is available at their website.

Installing scriptcs

Once Chocolatey has been installed, you can install the latest stable version of scriptcs from your command prompt:

cinst scriptcs

Chocolatey will install scriptcs to %APPDATA%\scriptcs\ and update your PATH accordingly.

Note: You may need to restart your command prompt after the installation completes.

Staying up-to-date

With Chocolatey, keeping scriptcs updated is just as easy:

cup scriptcs

Nightly builds

Nightly builds are hosted on MyGet, and can also be installed through with Chocolatey:

cinst scriptcs -pre -source https://www.myget.org/F/scriptcsnightly/ 

Building from source

Execute build.cmd to start the build script.

Getting Started

Using the REPL

The scriptcs REPL can be started by running scriptcs without any parameters. The REPL allows you to execute C# statements directly from your command prompt.

C:\> scriptcs
scriptcs (ctrl-c or blank to exit)

> var message = "Hello, world!";
> Console.WriteLine(message);
Hello, world!
> 

C:\>

Writing a script

using Raven.Client;
using Raven.Client.Embedded;
using Raven.Client.Indexes;

Console.WriteLine("Starting RavenDB server...");

EmbeddableDocumentStore documentStore = null;
try
{
    documentStore = new EmbeddableDocumentStore { UseEmbeddedHttpServer = true };
    documentStore.Initialize();

    var url = string.Format("http://localhost:{0}", documentStore.Configuration.Port);
    Console.WriteLine("RavenDB started, listening on {0}.", url);

    Console.ReadKey();
}
finally
{
    if (documentStore != null)
        documentStore.Dispose();
}
scriptcs -install RavenDB.Embedded
> scriptcs app.csx
INFO : Starting to create execution components
INFO : Starting execution
Starting RavenDB server...
.. snip ..
RavenDB started, listening on http://localhost:8080.

Bootstrap scripts with Script Packs

Script Packs can be used to further reduce the amount of code you need to write when working with common frameworks.

scriptcs -install ScriptCs.WebApi
public class TestController : ApiController {
    public string Get() {
        return "Hello world!";
    }
}

var webApi = Require<WebApi>();
var server = webApi.CreateServer("http://localhost:8888");
server.OpenAsync().Wait();

Console.WriteLine("Listening...");
Console.ReadKey();
server.CloseAsync().Wait();
scriptcs server.csx 
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Hello world!</string>

Referencing scripts

#load "controller.csx"
scriptcs server.csx 
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Hello world!</string>

Referencing assemblies

You can reference additional assemblies from the GAC or from the bin folder in your script's directory using the #r directive:

#r "nunit.core.dll"
#r "nunit.core.interfaces.dll"

var path = "UnitTests.dll";
var runner = TestSetup.GetRunner(new[] {path});
var result = runner.Run(new ConsoleListener(msg => Console.WriteLine(msg)), TestFilter.Empty, true,     LoggingThreshold.All);

Console.ReadKey();

Contributing

Samples and Documentation

Additional samples can be contributed to our samples repository. Documentation can be found on our wiki.

Community

Want to chat? In addition to Twitter, you can find us on Google Groups and JabbR!

Coordinators

Credits

License

Apache 2 License