Thursday, August 8, 2013

scriptcs in Two Minutes

Want to say you've used scriptcs? Follow this post and you can say that in about two minutes.

(For the longer version, go here: https://github.com/scriptcs/scriptcs)

At a command prompt, run this:
@powershell -NoProfile -ExecutionPolicy Unrestricted -Command "iex ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin
Then run this:
cinst scriptcs
That's it. Really. Now you can write C# at a command prompt:

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

> var message = "Hello, world!";

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

Want to save some C# and run it any time? Do this:

C:\Temp>copy con helloworld.csx
var message = "Hello, world!";
Console.WriteLine(message);

        1 file(s) copied.

C:\Temp>scriptcs helloworld.csx
Hello, world!

Note: I got an error when trying to run this at the root of the C: drive, so I just switched to my temp folder and it worked.

Enjoy!