Getting Started with Script#

Hello World with Script# - a 101-style walkthrough on authoring and deploying scripts compiled from c#, while using the HTML DOM APIs, XMLHttpRequest, and jQuery.

At MIX11, I presented a session on Script# titled "Script#: Compiling C# to JavaScript" ... and I did a follow up blog post highlighting the key points from the presentation.

This blog post covers the Hello World demo, which will show how you can get started with script#, and deploy scripts authored using this approach. It doesn't go into more advanced topics, but hopefully it will also demonstrate a couple of key principles at play:

  1. Script# doesn't introduce some new and odd abstractions. You're still very much authoring script against the DOM and standard APIs, and existing knowledge of web development carries forward.
  2. The generated script is similar to script you might have authored directly, and can be distributed or deployed into a web application like any other script library, without a dependency on the compiler at runtime.

Script# enables you to leverage Visual Studio, C# syntax and existing familiar and robust set of .NET tools to scripting. In my MIX talk, I demonstrated some of this. In this post, you'll see some basic benefits such as intellisense and compile errors.


Creating a Script# Project

I am going to start with a solution that contains an ASP.NET Web Application (DemoWeb), which is going to contain my pages and scripts. I can of course deploy script#-generated scripts into any server application.

Next I am going to add a Script Library project, named DemoScript. This is a project template that gets installed into Visual Studio when you install script#. The project template creates a C# project, with a custom msbuild target that invokes the script# compiler msbuild task after the C# compiler is done with its part to produce an assembly.

Add New Script# Project

DemoScript Project Deployment Options
Upon choosing to create a Script Library project, the Script# project template prompts for an optional deployment path. By default, the generated scripts are produced alongside the .dll assembly in the bin\Debug and bin\Release subfolders of the project. With a script# project, you can additionally choose to automatically deploy the generated scripts into a deployment folder, for example, into the /Content/Scripts folder within the web application, as I have chosen in the screenshot on the left. Demo Solution Structure

The script# compiler compiles the DemoScript project to produce debug and release versions of scripts, along with mscorlib.js which provides functionality like a type system in script, and basic utility APIs.

I also went ahead and added a couple of files to the Web project - Hello.htm, a simple page which will consume the generated script, and HelloService.ashx, a simple service that produces a JSON response when the client issues a request to it.

Here is the HTML markup in Hello.htm:

<head>
  <title>Hello Script#</title>
</head>
<body>
  <h1>Hello World</h1>
  <h2>Powered by Script#!</h2>
  <hr />
  <label>What is your name?</label><br /><br />
  <input type="text" id="nameTextBox" />
  <button type="button" id="helloButton">Hello</button>
</body>
</html>

And here is the implementation of the service in HelloService.ashx:

public class HelloService : IHttpHandler {
    public void ProcessRequest(HttpContext context) {
        string name = context.Request.QueryString["name"];
 
        object result = new {
            greeting = "Hello " + name + "! Its script# demo time...",
            timestamp = DateTime.UtcNow.ToString()
        };
 
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        string json = serializer.Serialize(result);
 
        context.Response.ContentType = "application/json";
        context.Response.Write(json);
    }
}


Authoring Script with Script#

With the solution and Web application setup work completed, and out of the way, we can now focus on using script# and authoring script.

The first step is to add a new Page class. You can think of a Page class as roughly equivalent to code-behind for a page.

Add New Page

This adds a class with the following template-based boiler plate code.

using System;
using System.Collections.Generic;
using System.Html;
using System.Runtime.CompilerServices;
 
namespace DemoScript {
    [GlobalMethods]
    internal static class HelloPage {
        static HelloPage() {
            // Add script that runs on startup as the script is loaded into
            // the page
        }
    }
}

In script#, static constructors get generated as code that runs immediately as the script is loaded and parsed. You can author regular classes with regular instance methods as well to create script types and functions, but we don't need to go there for this first introduction post.

As you start authoring code, there are some interesting things to call out. The HTML DOM APIs have been defined in the System.Html namespace (within the Script.Web.dll assembly that is automatically referenced in your project). This provides strongly typed access to the DOM as well as intellisense, and build errors if you have typos, missing parameters etc. as shown in the following screenshots.

Intellisense

Intellisense and Build Errors

Here is the initial code written to locate the button element from the markup, and then bind an event handler to its "click" event:

Element helloButton = Document.GetElementById("helloButton");
helloButton.AddEventListener("click"delegate(ElementEvent e) {
}, false);

Now we'll fill out the event handler to retrieve the text from the input element and invoke the service hosted on the server, and display the generated greeting from the server.

Element helloButton = Document.GetElementById("helloButton");
helloButton.AddEventListener("click"delegate(ElementEvent e) {
    InputElement nameTextBox = Document.GetElementById("nameTextBox").As<InputElement>();
 
    XmlHttpRequest xhr = new XmlHttpRequest();
    xhr.Open(HttpVerb.Get, "/HelloService.ashx?name=" + nameTextBox.Value.EncodeUriComponent());
    xhr.OnReadyStateChange = delegate() {
        if (xhr.ReadyState == ReadyState.Loaded) {
            Dictionary<stringstring> data =
                Json.ParseData<Dictionary<stringstring>>(xhr.ResponseText);
 
            string greeting = String.Format("{0}\r\nGenerated on {1}...",
                                            data["greeting"], data["timestamp"]);
            Script.Alert(greeting);
        }
    };
    xhr.Send();
}, false);

The key things to note here are this is very much like script you'd author directly - create an XMLHttpRequest instance, invoke a request, and process the response upon completion.

There are a few Script# specifics or benefits - notice the use of InputElement, which derives from Element (to add members like the Value property), and the use of enums like HttpVerb and ReadyState rather than literal values. These are present in the C# source code to improve readability and reduce possibility of errors, but effectively go away from generated script, and don't have runtime impact.

Here is the resulting script:

var helloButton = document.getElementById('helloButton');
helloButton.addEventListener('click'function(e) {
  var nameTextBox = document.getElementById('nameTextBox');
  var xhr = new XMLHttpRequest();
  xhr.open('GET''/HelloService.ashx?name=' + encodeURIComponent(nameTextBox.value));
  xhr.onreadystatechange = function() {
    if (xhr.readyState === 4) {
      var data = JSON.parse(xhr.responseText);
      var greeting = String.format('{0}\r\nGenerated on {1}...', data.greeting, data.timestamp);
      alert(greeting);
    }
  };
  xhr.send();
}, false);

The release script minimizes whitespace, as well as identifiers for local variables, internal members, types etc. as shown (whitespace added back for readability):

var $0=document.getElementById('helloButton');
$0.addEventListener('click',function($p1_0){
  var $1_0=document.getElementById('nameTextBox');
  var $1_1=new XMLHttpRequest();
  $1_1.open('GET','/HelloService.ashx?name='+encodeURIComponent($1_0.value));
  $1_1.onreadystatechange=function(){
    if ($1_1.readyState === 4) {
      var $2_0 = JSON.parse($1_1.responseText);
      var $2_1 = String.format('{0}\r\nGenerated on {1}...', $2_0.greeting, $2_0.timestamp);
      alert($2_1);
    } 
  };
  $1_1.send();
}, false);


Deploying and Using the Compiled Scripts

The next step here is to add a reference to the generated script in the page. Script# provides a script loader that loads scripts asynchronously, manages dependencies and more, but again, for this introduction, I am going to use vanilla script tags, to keep things simple, and highlight the fact that the generated scripts in fact work like any other script - with no dependency on the script# compiler at runtime.

<script type="text/javascript" src="/Content/Scripts/mscorlib.debug.js"></script>
<script type="text/javascript" src="/Content/Scripts/DemoScript.debug.js"></script>


Working with JSON Data in C#

The HelloService implementation returns a JSON formatted object with two members: greeting and timestamp. I am using a Dictionary<string, string> type to work against this JSON-formatted data on the client.

However I might want to create a proxy type and work with the JSON data in a strongly typed manner from a C# code perspective, without changing what happens at runtime.

I can define a proxy class as follows:

[Imported]
public sealed class ServerResult : Record {
 
    public string Greeting;
    public string Timestamp;
}

Essentially a Record class tells the Script# compiler that the class represents a vanilla JavaScript object, and consequently is limited to public fields (that correspond to the members). A record class can also have a public constructor, but we don't need that functionality here, as the record is representing the data produced by parsing the JSON response from the server.

Additionally, the [Imported] metadata attribute instructs the compiler that it doesn't need to generate any script for it. Its simply there to represent the shape of the object created from the JSON response.

To use this class, I simply need to change the code that handles the response to the following:

ServerResult data =
    Json.ParseData<ServerResult>(xhr.ResponseText);
 
string greeting = String.Format("{0}\r\nGenerated on {1}...",
                                data.Greeting, data.Timestamp);
Script.Alert(greeting);


Using jQuery

I'll do a follow up which covers jQuery in more depth (using jQuery and its Fluent API pattern for chaining calls, authoring jQuery plugins etc.) in the future, but I wanted to show how jQuery can be applied in this HelloWorld scenario.

The first thing I'll do is add a reference to Script.jQuery.dll, which contains all of the jQuery core APIs (updated to match jQuery 1.5.1, as of this writing), and then import the jQueryApi namespace.

Add jQuery Reference

Here is the equivalent functionality implemented using jQuery:

jQuery.OnDocumentReady(delegate() {
    jQuery.Select("#helloButton").
        Click(delegate(jQueryEvent e) {
        string name = jQuery.Select("#nameTextBox").GetValue();
        string url = "/HelloService.ashx?name=" + name.EncodeUriComponent();
 
        jQuery.GetData<ServerResult>(url,
            delegate(ServerResult data) {
                string greeting = String.Format("{0}\r\nGenerated on {1}...",
                                                data.Greeting, data.Timestamp);
                Script.Alert(greeting);
            });
    });
});

As you can see, it uses familiar jQuery patterns - once the document is ready, select an element, bind to an event, get data using an ajax request, consume data and so on. The other thing you'll also see is how jQuery simplifies the code... script# with jQuery lives up to the jQuery experience you might have had in the past.

The resulting script is the following (again, similar to what you might have implemented directly):

$(function() {
  $('#helloButton').click(function(e) {
    var name = $('#nameTextBox').val();
    var url = '/HelloService.ashx?name=' + encodeURIComponent(name);
    $.get(url, function(data) {
      var greeting = String.format('{0}\r\nGenerated on {1}...', data.greeting, data.timestamp);
      alert(greeting);
    });
  });
});


Summary

You can download the sample code for this blog here, and open the project on your machine, once you've installed script#.

Hopefully this blog post provides an introduction to getting started with using script#, compiling your c# to produce script, and deploying and running that script within your web application. Hopefully it also underscores the fact that script# doesn't introduce abstractions, and that you're still very much coding the same APIs, the HTML DOM, jQuery, XMLHttpRequest etc. and that the resulting script is a reasonable representation of your original source code. Stay tuned for more script# related content. In the meantime you can also follow me on twitter and/or follow script# on twitter to stay up to date with announcements and updates.

Posted on Thursday, 4/28/2011 @ 8:38 PM | #Script#


Comments

48 comments have been posted.

Daryl

Posted on 4/28/2011 @ 8:50 PM
This is an interesting project. I've been watching it for a while.

But honestly, I just can't imagine how anyone could invest any serious resources developing with Script#.

It's written by one guy, when he finds the time. There's no timetable for important features. There's no roadmap to speak of, and no source code. If he gets hit by a bus or something (let's hope not), your project is dead.

Hey, I understand this isn't your day job. Is there any reason it can't become a "real product", ie, get some support for adding it to VS, or open-source it?

Nikhil Kothari

Posted on 4/28/2011 @ 9:07 PM
The plan has always been to open source it. And its already on the path to being set up that way... see the MIX11 announcement first.

That said lots of teams have used it successfully for some large apps. The two things that helped: the productivity benefits outweighed the issues, and second, and this has been most important for the large teams - they could walk away from the tool with their latest snapshot of compiled scripts (which closely resembles their original source code), if there came a day where they decided directly working on the script in fact worked better. In other words they weren't betting the farm by picking up a development-time tool, rather than a dependency they need to carry around in their deployed product.

merill fernando

Posted on 4/28/2011 @ 10:59 PM
Awesome stuff Nikhil!

You truly are a legend.

PadovaBoy

Posted on 4/29/2011 @ 5:07 AM
I still don't understand why this project exhists:
- intellisense? it takes 30$ just to buy WebStorm of jetbrains and u have (also) a small resharper for jscript
- unit test? use qunit
- Continuous integration? create a c# unit test that lunches a browser where are the qunit tests

The cons of this project:
- u must know what is the javascript that u want to write and u must learn the 'fake' method in script# to simulate it
- the script# must be updated continuosly
- u have a new layer that can have bugs
- u try to write a code in a language that is different (in nature) to the final result: it can confuse you!

u cannot create castles with potatos

please explain me if i'm wrong

many tnx

Doug Wilson

Posted on 4/29/2011 @ 9:36 AM
I too have been following this project for awhile however it wasn't until your Mix11 demo that I really got my head wrapped around it. I think the move to open source it is a good one and I hope that the existing Script# community will quickly step up to begin filling in the gaps. I look forward to seeing what happens next hope that you'll keep up your great work!

Truly a fantastic gift to the .NET community! Thank you!

Nikhil Kothari

Posted on 4/29/2011 @ 9:40 AM
@PadovaBoy
I really don't think the useful question is "why the project exists" - but if you care about my perspective, its more than intellisense ... if you care to read the description of the project, you'll see why the breadth of tools is more interesting than intellisense alone. I also won't go into the deeper reasons of why compiling to script is interesting, and in the context of how script# isn't the only example of doing so ... if you really are interested, again there are past blog posts, and my MIX talk as well.

The real question IMO is why users use it (and there are many users building large and very real projects... also listed in my past blog posts). Only they can ultimately answer that particular question, since each team has unique requirements, and unique ways script# is providing value to the team... at the 10,000 ft level, these reasons converge into increased productivity and maintainability of code base. For many of the teams, this tool has been indispensable.

Of course, everyone's mileage and experience differs, based on your needs, your opinions etc. You're free to decide for your own situation. Not every tool is meant for everyone.

Erik Källén

Posted on 4/29/2011 @ 1:32 PM
It truly is great stuff, but is there a timeline of when to opensource it? I can't wait to start contributing.

Erik Källén

Posted on 4/29/2011 @ 1:38 PM
And, @PadovaBoy, say you have 20k LOC of JavaScript with an object carrying data like this:

{
key1: "Some string",
key2: 3,
value: "x"
}

and you want to transform it, and all 50+usages of it, to

{
key: {
first: "Some String"
second: 3
}
value: "x"
}

With C#, it is literally a 5 minute job to make the changes in all code paths, while in JavaScript it can easily take half a day to achieve a reasonable confidence that you have covered most of them. And no, unit testing is not the solution to this, because it would most likely show up as an integration bug, and integration testing is complex enough without having to test every possible code path.

Steve Gentile

Posted on 4/29/2011 @ 5:53 PM
Great post - keep publishing tutorials!

Listen to latest dev life on criticism :)

J/k but I do hope you open source it. This is closest we have to GWT for C#

Your last comment is very true

Steve

Posted on 4/30/2011 @ 5:53 AM
Using IE9, I get the following error:

Error: Object doesn't support property or method 'addEventListener'. Had to use Firefox to get this to work.

Also, I don't have a 'ServerResult' object? Can you update to provide location of this class ? (I see it in demo, but this is confusing, you skipped over the key elements in your getting started).

Additionally, you might want to explain in the jQuery section that a reference to the jQuery library is needed.

So my criticism is, if you write an article 'getting started' you should try to cover everything and not make assumptions that people will just assume they need some 'proxy object'.

Otherwise good.

Thanks

rekna

Posted on 5/1/2011 @ 10:48 AM
If anyone needs a good reason why scriptsharp might exist : recently jqgrid ( a very good grid plugin for jquery ) changed some methods from old syntax to new syntax:
an example:
old method : jQuery(”#grid_id”).jqGrid('getPostData')
new method : jQuery(”#grid_id”).jqGrid('getGridParam','postData')

if I had written everything with scriptsharp in my project, I could have changed this quite easily... just remove the old method and compile, and all places where the code would be broken just show up in the compiler output as errors...
instead, now I have to sift through each and every javascript file in my project, looking for places where I still use the old syntax... and change it, with the chance to introduce new typos...

Nikhil Kothari

Posted on 5/1/2011 @ 3:14 PM
@Steve,
Not sure what you're referring to:
- The post mentions the code for creating a ServerResult and why I am using a proxy type, and it is also in the sample code if you download it.
- Also, the post specifically talks through adding a reference to Script.jQuery.dll (with a screenshot to go along!)

phil

Posted on 5/2/2011 @ 1:21 AM
@rekna
I'd rather write my own grid control using Script# than using jqgrid(Im really considering this). :P
I have really bad experience with jqgrid, awful setup, configuration, lots of overhead, and then u dont know why something is not working....

Daryl

Posted on 5/2/2011 @ 7:41 AM
Open-source is nice, but honestly I think for this to go anywhere, it needs to be adopted by MS into the Visual Studio "family".

This gets into the bigger question. The elephant in the room. "What now, ASP.NET?"

Here's HTML5 and IE9, and Chrome with all their support for canvas and video and building rich, client-side apps on the web. And no one know how any of this is going to work with ASP. This much is clear: ASP wasn't designed for HTML5. It's designed for lots of postbacks, it's designed for events running server-side. Client-side events are an afterthought and you write them in JavaScript on your own.

In short, ASP.NET as it exists now is completely inappropriate to HTML5 sites. I think even the ASP team knows this. The question which hasn't been answered yet is, what is Visual Studio 2012 going to do about it?

Script# is going in the right direction, but the one-person development model is hopeless. No offense to the NK: you've done a yeoman's job but after 6 years there are still huge gaps, and HTML itself is changing every few months. One person working really really hard will never keep up.

Nikhil Kothari

Posted on 5/2/2011 @ 8:32 AM
@phil
Would love to see components built in script# rather than just a wrapper. Eventually, I hope there will be ability to do static linking, it will help to have code rather than just stubs, that can be static linked.

@Daryl
Hence the reason for open sourcing. Hopefully the new community around the web is one where everything doesn't have to be baked in into VS, i.e. its a bit different from the typical .net/windows enterprise customer set. If open sourcing also doesn't motivate the right community, then yes, you're right, the only way to move it forward would be for script# to be a product, not a project, a topic on which I am not going to comment on over here. I'm going to give it a chance and see where it goes. As for ASP.NET and its app-model, I think that is a bit off-topic here.

PadovaBoy

Posted on 5/2/2011 @ 9:02 AM
@Nikhil, tnx for the past answer.

Another question for u: i love KnockoutJs, what if i want to use it? Do i have to wrap its own api too, before start a project that use it?

tnx

Michael Murray

Posted on 5/2/2011 @ 4:47 PM
@phil

Script# controls are exactly what the company I currently work for are focusing on - the only way to go!

#1 for me is that Script# helps keep all our JavaScript really organised - refactoring is a dream. The shear number of collaborators on some projects also mean that it is difficult to get everyone to conform to the same standards, but Script# helps us do this too...
Keeping people away from hand coding javascript has also a triggered better architecture in that we are grouping scripts that used to be scattered around, into plugins and libraries.
We are avoiding the runtime script synchronisation issues that we used to have with UpdatePanels and that kind of thing, by replacing that kind of functionality with controls that have a single load of javascript and markup then use Ajax calls returning Json for everything else (a little like EXTJS approach). I am also working on a project using MVC3 to unify the whole lot - one call for your markup and script view and then all other calls back to the same controller for JsonResults - awesome and something I would have bothered looking at if it wasn't for the change in mindset that using Script# has triggered.

Keep up the good work Nikhil! I don't care whether it goes open source or not, so long as you can keep it alive!

Chris Marisic

Posted on 5/3/2011 @ 7:33 AM
I'm in the same boat as @PadovaBoy that I could see tremendous value in this project with the way client side web development going I feel that KnockoutJs is definitely a natural evolution of programming and to lose what it brings to the table I don't think could justify being able to write c# code as javascript.

The other concern I have, does script# further obscure having properly scoped javascript along with using closures correctly?

Nikhil Kothari

Posted on 5/3/2011 @ 8:32 AM
@Chris
Script# is a compiler. Knockout is a framework. As a compiler it is agnostic of frameworks... so if you want to use a particular framework, that is your choice.

Your other question is rather general, and unclear - best thing to do is check for yourself IMO regarding your specific code scenario and concern, and if that is still the case, open an issue on github explaining the problem... so it can be actioned upon.

kaneboy

Posted on 5/10/2011 @ 7:17 AM
Hi Nikhil, great session and great script#!

I installed Script# on my dev box and have a question. As your demo project, I created a web application project and a Script# library project. When I use "Page" or "jQuery Page" project item to add new classes into Script# library project, all these classes are compiled to one single .js file. How should I do if I just want to build a separated .js file for one specific aspx page in the web applicatoin project? I cannot find a way to build separated .js file and reference it on a .aspx page in web application project.

Nikhil Kothari

Posted on 5/11/2011 @ 8:44 AM
@kaneboy
I'll tell you the steps you need to take to make this work for a regular Script Library project:

1. Open the csproj and add a property: <WebAppPartitioning>True</WebAppPartitioning> (the Web App project already does this, but I'll be removing that template as it causes some confusion.)
2. For each folder in the project, the build task will create a separate script. Be sure to not reference code from one folder in another folder... it will cause compiler to fail.
3. If you really want to have something shared across folders, put it in the Shared folder. That code will be included in every script produced.

Hope that helps.

kaneboy

Posted on 5/12/2011 @ 1:23 AM
@Nikhil
Thanks for your reply. It works perfectly!

phil

Posted on 5/16/2011 @ 12:19 AM
This is probably not the right place for problems, but when trying to compile a jquery library project, it gives me some errors
Missing compiler required member 'System.NotSupportedException..ctor
Missing compiler required member 'System.Threading.Thread.get_CurrentThread
...
A plain JQuery app project works, maybe my code could cause this, thought it's just a few files and lines.

djgtram

Posted on 5/23/2011 @ 5:26 AM
And what can I do if Script# doesn't appear in VS C# 2010 Express? Installs without error message there is no sign of it in Add New Project (as depicted in the first picture above). The VS installation is completely OK otherwise, I use it all the time. W7/64 Ultimate, if this makes any difference.

Paul Sullivan

Posted on 6/30/2011 @ 5:13 PM
Calling jQuery.ajax("url", opts) where opts has no url causes xhr to / of application rather than the "url" in latest version (0.7 or something)

Steven

Posted on 7/1/2011 @ 8:16 AM
Is there a way to use a script# project for multiple web projects in different solutions? As the DeploymentPath seems to be hardcoded in the project file, is there another way to enable the web project to use the generated scripts?

Nikhil Kothari

Posted on 7/2/2011 @ 9:56 AM
@phil - no idea but you're probably doing something in your c# code that makes the c# compiler to look for various APIs that aren't supported by the script# mscorlib (since something like threading doesn't apply).

@djgtram - will have to look again and see if something changed with vc# express in 2010.

@Paul - seems like a jQuery issue.

@Steven - The deployment path is just one option. You can customize exactly what you want to do for your specific scenarios by customizing the csproj and msbuild process. That is a benefit of building on top of msbuild. The standard build customization and extensibility can be applied to script# projects and script building as well.

zdw

Posted on 7/2/2011 @ 10:04 AM
When I use script# to complie source code with chinese character in it,I get this.
"\ufffd\ufffd\ufffd\ufffd"
Could you help me to solute this problem?Thanks!

monkey

Posted on 7/7/2011 @ 1:35 PM
i got "Line: 84: Error: Object doesn't support this property of method" error when I run the bing map sample. I run others fine.

the JS code at line 84 is: window.addEventListener('load', function(e) {

GLeBaTi

Posted on 7/14/2011 @ 5:20 AM
Hello!
In javascript i write this:
var canv = document.getElementById('canvasID');
var context = canv.getContext('2d');
context.fillRect(...);

And how can i rewrite this in script# ?

Jerry Evans

Posted on 7/31/2011 @ 7:02 AM
Nikhil - Many thanks.

0.7x is starting to look really useful. It is great that the libraries etc have finally been open-sourced, long overdue in my opinion!

Some comments if I may.

1. You are doing yourself a great disservice by not making more of the 'AroundMe' example. This is a fantastic resource and (IMVHO) really plays well to the strengths of script#. This should be included in the Github repo along with a simpler client-side only 'Hello World' example.

2. The project desparately needs some detailed documentation. I stumbled across a PDF dating from 2006 on Google Code (?) entitled ScriptSharp-v0.4.2.pdf. How much of this is still relevant/accurate I am unsure but it too should be in the Github repo.

3. Appoint a documentation/example code Czar to stop things from getting too fragmented. Give them access to the repo and entrust them to maintain a 100% out-of-box experience. i.e. ensure that a) any sample runs first time and b) there is at least a page explaining what the code does
and how the components hang together.

4. Where you do have examples (MIX11) make sure they work! If I open up demo.sln I see DemoWeb set as the startup project. If I hit F5 to run it I get a listing of the project files in my default browser (Chrome) and it is only when I select Hello.aspx that something Script# related actually happens.

Hope this is constructive stuff. There is good possibility of using Script# for a green field project and I'd like to be able to give management as much comfort as possible. Open-sourcing the tooling would be a great help - otherwise we have the worst of all worlds (non-commerical, unsupported) which plays right into the hands of Sharpkit and friends ....

ATB

Jerry

Jim

Posted on 8/4/2011 @ 4:39 PM
Script# has a bug with Bing maps.

If you create a polygon and want to specify the color, the MapPolygonOptions object wants a 'MapColor' object for the FillColor property. The problem is that the MapColor object gets translated to a 'Microsoft.Maps.MapColor' object in the resulting javascript, which throws an exception since the map requires a 'Microsoft.Maps.Color' object.

Is there a workaround?

Nikhil Kothari

Posted on 8/13/2011 @ 10:26 AM
@Jerry Evans
Thanks for the constructive feedback - working on the docs, and samples (incl. the AroundMe app)

@Jim
Could you log a bug on the github site? Also, this should be easily fixable since the sources are all shared, so you could fix on your end, and if you do contribute back so everyone benefits, rather than be blocked.

mvbaffa

Posted on 8/19/2011 @ 4:51 AM
Hi,

Your product is outstanding, but we need more documentation. We beggining to working with Knockout. Can you please post some sample of using Knockout with ScriptSharp.

Thanks in advance

Felix Marianayagam.J

Posted on 8/26/2011 @ 2:21 AM
Awesome stuff Nikhil! I occasionally pick some ideas and use it as an example during our .NET training (see http://www.wafytech.com/training) program. Thanks for the wonderful post.

Felix.J, PMP
http://www.wafytech.com

Wesley Bakker

Posted on 8/29/2011 @ 11:23 AM
Nikhil, as I'm investigating Script# it looks very promising. The only problem is wih documentation and finding the open source version. Still don't know where to find the open source version. The other issue I'm having is that I cannot add a second page to the project.

I expect to get a separate .js file for each Page I add. It does not make sense at all to me that all seperate Page classes are compiled into one JS file. It's like I have to create a single code behind file, that gets used by all pages/views in my project. That's not how webforms work and not how MVC works so why is this behavior different in Script#? Yep I've found your answer regarding the project <WebAppPartitioning>True</WebAppPartitioning> setting. But that means I have to create a separate folder for each and every page, which does not make sense and is very hard to maintain.

So is there an easy way to actually add a new Page that indeed creates a separate .js file for it? Tried to look for an attribute but couldn't find one.

I really see a huge potential in using Script#.

Thanks,
Wes

Lucian

Posted on 8/31/2011 @ 8:09 PM
Hi Nikhil,
your project is great! I am considering to use it for complicated part of my project.
How about apply it to Node.js? that would be quite interesting!

Andrea Del Signore

Posted on 9/22/2011 @ 7:15 AM
I found script# just yesterday and I think it's very useful for big RIA applications.

Now I'm trying to make some proof of concepts binding big JS framework like qooxdoo or SproutCore, but I've several (expected) questions and problems.

The first one is: given this SproutCore snippet

Todos.Todo = SC.Object.extend({
title: null,
isDone: false
});

How can make script# generate the initialization block?

{
title: null,
isDone: false
}

I have no clue on what C# syntax should I use or if there is some [Attributes] that can instruct the compiler make the magic.

On a side note: an official forum is needed (or should I use the issue on github?)
And more: you should opensource the compiler... sooner is better than later ;)

Thanks a lot,
Andrea

Andrea Del Signore

Posted on 9/22/2011 @ 8:24 AM

Gonzalo Rodriguez

Posted on 10/2/2011 @ 6:57 AM
Excelent work Nik,

A year ago I was playing with script#, but after watching the MIX11 video and seing the roadmap I decided to consider the tool for a new project. I am really excited because after less than two hours I could write my first proxy for openlayers.js and write a web map mashup application without writting a single line of javascript code.

Thanks again,

Gonzalo

Alexey Grachev

Posted on 10/3/2011 @ 7:32 AM
Hi Nikhil,
Thank you for S#.

I am going to use it for client side Sharepoint 2010 development but I am in doubt whether it will work on the top of the Microsoft Ajax 3.5 Library (which is used by Sharepoint 2010 client side framework)
After addition of S# mscorlib.js to web part page I can not add any new webpart on the page (and it works appropriately when I remove a reference to mscorlib.js)

I know that you have decided to not support Microsoft Ajax Library in S# but what about co-existing of the both these client side runtime libraries (mscorlib.js and Microsoft.Ajax.js(that comes with Sharepoint)) in the same environment? Does S# handles this situation?

Thank you once again.

xThePeoplesx

Posted on 10/10/2011 @ 2:47 PM
Nikhil, I used to program with scriptsharp back around 0.4.x.x... The ProblemI have now is all my code is old and uses deprecated code. So Where should I look at building new client side scriptsharp for my controls? I used to use "ssfx:ControlReference" to bring in controls in my dictionary argument constructor. Now that is gone as is "Control". I have no idea where to start now that there is 0 documentation and all the old code has been removed or changed.

So I guess a good starting point would be, how do I take an argument in for the constructor? I am trying to have the scriptsharp be my whole client side script for a control control library. One script per control... But I need to first grab the control and then its children...

Brad

carlton

Posted on 10/26/2011 @ 11:26 AM
Where is the documentation? There used to be a very nice pdf that went into significant detail about how to use Scriptsharp. I can't find anything now, no pdf, no chm. I'm sure it is there, but I can't find it. Can someone provide a link to the reference docs, not just the tutorial or sample projects?

Fox

Posted on 11/25/2011 @ 2:59 AM
What about Visual WYSIWYG Layout of GUI Components ?

R. Lawson

Posted on 12/4/2011 @ 8:15 PM
Someone posed the question:

"I still don't understand why this project exhists:
- intellisense? it takes 30$ just to buy WebStorm of jetbrains and u have (also) a small resharper for jscript
- unit test? use qunit
- Continuous integration? create a c# unit test that lunches a browser where are the qunit tests"

I think the idea is brilliant.

Clearly this person believes in tightly coupling JavaScript to the browser. JavaScript is a language that can be used outside the browser, but currently that is the primary function. Even so, why not separate an area of concern? Are you seriously saying that the build server is going to kick off the browser to execute every test? We have compiler support with C# and a very mature unit testing framework. Where we have typed objects and something we like to call "scope".

If JavaScript had even an Interface class, that would help. The one gotcha I see with ScriptSharp has to do with the JavaScript limitation of no interface. So I suspect it would be difficult to keep up with future releases of frameworks you import.

طراحی سایت , بهینه سازی سایت

Posted on 12/7/2011 @ 1:29 AM
great tutorial... tnx

Victor Ortiz

Posted on 2/8/2012 @ 12:01 PM
I am wondering about how to import an existing script library in order to use it in Script#. Is there a tool or a process to take an existing script(s) and produce the appropriate Script# classes? I am looking to create a library project (like BingMaps and Knockout) for one set of scripts, and convert existing scripts to Script# for the other set of scripts for refactoring and further development. I found some old documentation (v0.5.5.0) on www.scribd.com, and I haven't be able to find anything more current. Could you please point me in the right direction? Thank you very much

Nikhil Kothari

Posted on 2/20/2012 @ 12:42 AM
@Victor Ortiz
Best doc is the existing code for all the libraries - see the github project for script# at https://github.com/nikhilk/scriptsharp.
Post your comment and continue the discussion.