Introduction to Script#

Sep 13, 2011 Posted by Lara Kannan

Have you heard about Script#?

I knew that there is a Java-to-Javascript converter called GWT (Google Web Toolkit) in Java World since long time back and I thought that it might be good if we, the C# developers, also have that kinda tools for ASP.NET web development.

Now C# developers can do the same using Nikhil Kothari's Script# project. This is not quite the same as using Atlas with ASP.NET though both cover similar territory.

Nikhil has written a C# compiler that outputs JavaScript instead of IL code. JavaScript is a powerful but not very friendly scripting language and Ajax is a technology that updates part of web pages from a web server without redrawing the entire page.

Script# is a compiler that generate the Javascript instead of MSIL from C# sourcecode. Like GWT (Google Web Toolkit) that can convert the Java code to browser-compliant JavaScript and HTML, Script# is able to convert the C# codes to Javascript (either human-readable format or compact one). It is the best tool for those who hate to write the Javascript in HTML view.

How it works?

Script# works by compiling C# source code and files directly into a single JavaScript file, in much the same way as the C# compiler that generates MSIL into a single assembly.


The inputs into the C# compiler are your source files, and any referenced assemblies. The referenced assemblies represent either script APIs in existing script files written manually, or script APIs defined within another Script# project with a corresponding generated script file.

The regular C# compiler is used to produce an assembly for your code and the XML doc-comments file that can then be used to produce documentation. The Script# compiler on the other hand generates a .js script file. All the script files - existing and generated – can then be deployed into a Web site or Web application running on any platform for use at runtime without any Script# dependency.

During compilation, the C# compiler and Script# compiler together provide build-time type checking and validation of your code. This helps catch typos and other common script errors at build-time on the development machine as opposed to at runtime on the end-user's machine.

The Script# compiler produces both release and debug versions of your script. The release version is minimized by removing whitespace and by reducing identifier lengths for internal and private members with shorter names. The debug version is formatted for readability and debuggability

The Script# System

Logically speaking there are three layers to the Script# system:

  • The Compiler

  • The Core RunTime

  • The Framework


Script# Compiler - The compiler compiles C# code into JavaScript, and is only needed on the development or build machine. The compiler assumes the existence of APIs defined in the Script# core runtime to represent classes and other OOP constructs defined in the originating C# source code.

Script# Runtime - At development time, the runtime provides the equivalent of mscorlib.dll. It defines various key .NET types such as System.Object, primitive types and other core BCL types needed to author and compile C# source code.

At runtime, the core runtime is a small bootstrapper script file that implements how various OOP constructs are defined and simulated in JavaScript, as well as providing basic extensions to existing JavaScript objects to implement functionality expected by .NET developers.

The default Script# runtime is implemented in sscorlib.dll and its accompanying runtime counterpart sscorlib.js. To use Microsoft ASP.NET Ajax, the equivalent pair consists of aacorlib.dll and MicrosoftAjax.js as its runtime counterpart.

Runtime assemblies shipping with Script# representing other script APIs such as Virtual Earth, RSS Feeds etc. ship in assemblies named ss*.dll.

Script# Framework - The framework is completely optional. The choice of framework also depends on the application and the developer. The compiler itself is not bound or dependent in any way against any particular framework choice. The default ScriptFX framework accompanying Script# ships in assemblies and scripts named ssfx.*.dll and ssfx.*.js.

Using Script#

Script# can be used either via the command-line (ssc.exe) or via MSBuild (via a custom task added to your .csproj profile file). The MSBuild approach is recommended.

Sourcecode Download : SSharp.zip

For more reference click here

Share
  1. I am happy to know. thank you so much for giving us a chance to have this opportunity.. This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points.


    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery


Post a Comment