At MIX11 last week, I presented the Script#: Compiling C# to JavaScript using Visual Studio.
As full-fledged script-based development becomes widespread with the HTML5 wave, a couple set of interesting questions emerge - what are the development tools you and your team uses to productively author and manage a code base? Shouldn’t you write code in a model that is optimized for development and productivity and let a compiler do its magic and produce code that is optimized for deployment and runtime?
Script# allows you to write your code in C# and compile it down to deployable JavaScript, it also unlocks the power of C#, Visual Studio and existing .NET tools for scripting scenarios.
Productivity and better tooling are primary motivators behind Script#. At the same time, a fundamental design tenet and driving philosophy behind the design of Script# is to produce script that resembles hand-written script that is aware and faithful to the script runtime environment found in browsers. Specifically the compiler does not introduce unnecessary layers of abstraction or indirection. The idea is you’re simply writing script in a better and pragmatic way, rather than trying to port a .NET application to the browser, which is more likely to produce impractical results.
Script# allows programming against the DHTML DOM APIs and JavaScript APIs, as well as Silverlight 1.0 script API. The compiler itself isn’t coupled to any one particular framework. You can use Script# to program against Microsoft ASP.NET Ajax as well as other 3rd party frameworks such as ExtJS (via Ext#). At the same time, the compiler is complemented by an optional ScriptFX framework, which is a small framework built using Script# itself. Finally, if you have existing scripts, they can be imported and then used from new C# code so you don’t have to rewrite everything from scratch to start using Script#.
Scripts generated using Script# are honest-to-goodness plain old JavaScript files, that you can freely deploy into your applications, and there is no runtime dependency on the Script# compiler. This is further explained in the Understanding Script# page. You will need .NET 2.0+ and/or Visual Studio on your development machine. You can also use Visual C# Express which is available for free.
Script# is an evolving project, but is quite mature and ready for use in real-world projects such as those listed in the showcase. Script# is being used both internally within Microsoft as well as external applications. It was first released in May 2006 (introductory blog post). Over the course of the last two+ years, it has been regularly updated with new features and bug fixed based on actual usage and feedback from developers like you. You can read about the latest release on the release history page. Please do continue sending any feedback on Script# that you might have.
The content on this site will be updated periodically to include additional concepts and tutorials. Please subscribe to the Script# feed to stay up-to-date or check this page often.
A set of samples available with the Script# install demonstrate some of these uses of Script# further. Read the topic on What's in Script# to understand more about what is currently available.
An in-depth list of how C# constructs are mapped to JavaScript is described on the topic From C# to Script. On the flip side, an in-depth list of how script constructs are modeled in C# is described on the topic Achieving Script’isms in C#.
The Script# project has been an on-going piece of work. The following are on the list for a v1 release during 2009 beyond what is available in the current and latest build:
Longer term, there are a number of additional features on the roadmap such as: