Delay's Blog is the blog of David Anson, a Microsoft developer who works with the Silverlight, WPF, Windows Phone, and web platforms.
http://dlaa.me/
@DavidAns
I published CSI, a simple C# interpreter, exactly one year ago. In that introductory post, I explained how CSI offers a nice alternative to typical CMD-based batch files by enabling the use of the full .NET framework and stand-alone C# source code files for automating simple, repetitive tasks. CSI accomplishes this by compiling source code "on the fly" and executing the resulting assembly seamlessly. What this means for users is that it's easy to represent tasks with a simple, self-documenting code file and never need to worry about compiling a binary, trying to keep it in sync with changes to the code, or even tracking project files and remembering how to build it in the first place!
Aside: The difference may not seem like much at first, but once you start thinking in terms of running .CS files instead of running .EXE files, things just seem to get simpler and more transparent! :)
And I'm happy to say that today, on the first birthday of CSI's public introduction, I'm releasing a new version!
[Click here to download CSI for .NET 4.0, 3.5, 3.0, 2.0, and 1.1 - along with the complete source code and test suite.]
Notes:
CSI40.exe
-R
Microsoft.CSharp.dll
System.Xaml.dll
Main(string[] args)
Main()
CSI11.exe
CSI.exe
CSI30.exe
CSI20.exe
System.Data.DataSetExtensions.dll
-r System.Data.DataSetExtensions.dll
For fun, here's an example of the new Main() support:
C:\T>type Main.cs public class Test { public static void Main() { System.Console.WriteLine("Hello world"); } } C:\T>CSI Main.cs Hello world
And here's an example of the new ability to run WPF code. Note that I've used the RegisterCSI.cmd script (included with the release; see here for details) to register the .CSI file type with Windows to make it even easier to run CSI-based programs. (And by the way, check out how easy it is to output the default style of a WPF control!)
RegisterCSI.cmd
C:\T>type WpfDefaultStyleBrowser.csi using System; using System.Windows; using System.Windows.Controls; using System.Windows.Markup; using System.Xml; class WpfDefaultStyleBrowser { [STAThread] public static void Main() { Style style = (new FrameworkElement()).FindResource(typeof(ContentControl)) as Style; XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.NewLineOnAttributes = true; settings.OmitXmlDeclaration = true; XamlWriter.Save(style, XmlWriter.Create(Console.Out, settings)); } } C:\T>WpfDefaultStyleBrowser.csi <Style TargetType="ContentControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <Style.Resources> <ResourceDictionary /> </Style.Resources> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate TargetType="ContentControl"> <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" /> </ControlTemplate> </Setter.Value> </Setter> </Style>
Finally, here's the contents of the "read me" file, with the CSI syntax, release notes, and version history:
================================================== == CSI: C# Interpreter == == David Anson (http://blogs.msdn.com/delay/) == ================================================== Summary ======= CSI: C# Interpreter Version 2010-01-04 for .NET 3.5 http://blogs.msdn.com/delay/ Enables the use of C# as a scripting language by executing source code files directly. The source code IS the executable, so it is easy to make changes and there is no need to maintain a separate EXE file. CSI (CodeFile)+ (-d DEFINE)* (-r Reference)* (-R)? (-q)? (-c)? (-a Arguments)? (CodeFile)+ One or more C# source code files to execute (*.cs) (-d DEFINE)* Zero or more symbols to #define (-r Reference)* Zero or more assembly files to reference (*.dll) (-R)? Optional 'references' switch to include common references (-q)? Optional 'quiet' switch to suppress unnecessary output (-c)? Optional 'colorless' switch to suppress output coloring (-a Arguments)? Zero or more optional arguments for the executing program The list of common references included by the -R switch is: System.dll System.Data.dll System.Drawing.dll System.Windows.Forms.dll System.Xml.dll PresentationCore.dll PresentationFramework.dll WindowsBase.dll System.Core.dll System.Xml.Linq.dll CSI's return code is 2147483647 if it failed to execute the program or 0 (or whatever value the executed program returned) if it executed successfully. Examples: CSI Example.cs CSI Example.cs -r System.Xml.dll -a ArgA ArgB -Switch CSI ExampleA.cs ExampleB.cs -d DEBUG -d TESTING -R Notes ===== CSI was inspired by net2bat, an internal .NET 1.1 tool whose author had left Microsoft. CSI initially added support for .NET 2.0 and has now been extended to support .NET 3.0, 3.5, and 4.0. Separate executables are provided to accommodate environments where the latest version of .NET is not available. Version History =============== Version 2010-01-04 Add .NET 4 (Beta 2) version Minor updates Version 2009-01-06 Initial public release Version 2005-12-15 Initial internal release