Executing a .CS file

There is VBScript, JScript and PHP. But there isn't anything like C#-Script. So, I decided to play around a bit, only as a matter of checking out the possibilties. The plan:
Create a CS-Script.exe file that we can use to ' launch ' a .cs file. Without having to add the file to a solution or anything. A very basic tool, that can launch one .cs file. View it as some sort of batch scripting tool. Where you can quickly open notepad, write something and run it.

We want to let the user know when he mucks up and doesn't provide an argument, so we add a reference to System.Windows.Forms and display a MessageBox .

The first thing we have to do is setup the compiler. Here I've put some restrictions. Every file should have a class CScript with a public void Main in it. If you want to extend this, be sure to get rid of that ;)

Another important parameter is the assemblies we involve in compiling our source. A "good" thing would be to put the most important namespaces in your project with using. We're going to include all the ones our project uses.

But some people don't make mistakes, and we run their code.
The compiler gave back an Assembly to use. It's very simply to invoke this one.
One strange issue, even thou we have set GenerateInMemory , it does create a file on our harddisk (at least here), so we have to clean that up.

by dmusunuru (0 replies)

by jawaugh (0 replies)

by Mickster1969 (0 replies)

Published 2 years ago, running time 0h56m

While at CodeMash, Carl and Richard collected some great stories. First up is Evan Huack, who digs into cudafy, a library on codeplex that allows you to run C# code (any IL code actually) on your GPU. The second story is about Jessie Shternshus and her company The Improv Effect. Jessie talks abou.