Make C# source run as a script?

> copy con cs.bat
csc -o OUTPUT.exe %1
OUTPUT.exe
del OUTPUT.exe
^Z
> cs somefile.cs

Here is a better version of a batch file:

@echo off
echo using System; class P { static void Main() { > foo.cs
type %1 >> foo.cs
echo }} >> foo.cs
csc /nologo /out:foo.exe foo.cs
del foo.cs
foo.exe
del foo.exe

So you have some file called foo.txt:

Console.WriteLine("Hello world");

Invoke it like:

cs.bat foo.txt

Well there's CS-Script. http://csscript.net/

Haven't used it much myself though.


Mono has CsharpRepl which is an interactive shell for C#

Tags:

C#

.Net

Scripting