C# Scripter: How to execute C# as batch files with my new utility – level 200

UPDATE:  This utility has been upgraded to support more .Net languages.  See here for the newer version.

The Windows shell has some great programming capabilities, and we can do a lot with it, but these days, I can whip something out with C# and basically do anything I need to with files.  It takes me considerably longer to do the same thing with DOS commands (mostly because I don’t know advanced shell scripting).  When Monad comes out in the next version of Windows, we’ll have .Net integrated into the shell, but that is many years away.  I’m left wanting to execute C# batch-style.

It’s no problem to create a console app and run it, but I want to have the .cs file available for tweaking, so it’s not feasible to just create a bunch of .exe files.  I needed a true C# scripting solution.

I now introduce the Palermo C# Scripter.  On the command line, it’s csscripter.exe, and it takes as an argument the name of the C# file.  For example:  csscripter.exe myBatch.cs

myBatch.cs just has be a valid console class like the following:

    1 using System;

    2 using System.Collections;

    3 using System.IO;

    4 using System.Windows.Forms;


    6 public class Whatever

    7 {

    8     public static void Main(string[] args)

    9     {

   10         Console.WriteLine(“Other Script file executed. ” + string.Join(“|”, args));

   11         MessageBox.Show(“You can even do pop-ups”, “With a title”);

   12     }

   13 }

I’m using this now to traverse thousands of nested files searching for little things and doing small things when I find something.  This is the same stuff I’d do with batch files, but now I have the power of C# in text form doing it for me. 

You can download the utility from me here.

If you have feedback or a feature request, please leave me a comment.  In putting this together, I came across some good references on C# scripting: