This project is read-only.

CSRun - C# Script Runner

This project was designed to provide users an easy way of executing C# programs that are compiled on the fly. This program can be used when scripting Windows Batch Files, Powershell Scripts, VBScript and others.


This extremely simple program uses the Microsoft.CSharp compiler. It allows for a user to specify the CS file, namespace, class, main method and necessary references needed to compile. It can be used in the following way:

csrun TestScript.cs -n Test -c TestScript -m Main -r System.Net.dll

 

The contents of the TestScript.cs are as follows:

using System;
using System.Net;
using System.Net.Mail;

namespace Builder
{
    public class PostBuild
    {
        public static void Main()
        {
			try
			{
				NetworkCredentials creds = new NetworkCredentials("JohnDoe", "password");
				SmtpClient client = new SmtpClient("smtp.gmail.com",587);
				MailMessage msg = new MailMessage("johndoe@gmail.com","janedoe@gmail.com");
				msg.Subject = "Question!";
				msg.Body = "Whats for dinner?";
				client.Send(msg);
			}
			catch(Exception ex)
			{
				Console.WriteLine("Could not send mail.");
				Console.WriteLine(ex.ToString());
			}
        }
    }
}

Last edited Oct 12, 2012 at 7:21 PM by akanieski, version 5