-
Notifications
You must be signed in to change notification settings - Fork 178
Creating your first HTML5 Application: Hello World
In this tutorial, we will get started with a new Script# HTML5 Application project and continue working towards building a basic spreadsheet application.
- Using the development branch
- Understanding of the [AMD Pattern] (http://requirejs.org/docs/whyamd.html)
- Familiarity with [RequireJS] (http://www.requirejs.org/)
-
AssemblyInfo.cs contains assembly level information for the C# DLL that's generated when the project is built. In our project, the file name will be called Spreadsheet.DLL. In addition, it also defines a script template which will be used for the generated file.
-
FxCop.ruleset contains code analysis rules. Generally, you can ignore this file.
-
Script.Web is a reference to the Script# HTML Library. You can explore the available API's explosed by that library by double clicking that reference and viewing it in the Object Browser.
-
packages.config contains package references. You will not need to modify this file. It is automatically updated as you add or remove references. In addition, Nuget will use this file to automatically download project references.
-
Page.cs is a static class with a static constructor that gets executed when the resulting Javascript file is loaded.
Let's add an alert in the constructor:
Window.Alert("Hello World...");
Now, build the application and look inside the bin\Debug folder:
You will notice that there's a file called Spreadsheet.js. Let's open this file and take a look at it:
Notice that the Window.Alert ("Hello World...") was translated to alert('Hello World...')
Create a static HTML file called Spreadsheet.html and set its "Copy to Output Directory property" as "Copy Always":
Add the following script tags to the head section of Spreadsheet.html
<script src="http://requirejs.org/docs/release/2.1.9/comments/require.js"></script>
<script src="ss.js"></script>
<script src="Spreadsheet.js"></script>
-
require.js is an Javascript File and Module Loader that will allow us to load modules defined using the AMD pattern.
-
ss.js is short for ScriptSharp.js. It provides us with some utility functions so we can potentially continue to think in C#. For example, Script# allows us to use Queues, but Javascript doesn't have a concept of queues. This Queue functionality is implemented in ss.js and the API is exposed via mscorlib.
-
spreadsheet.js is the Script# compiler generated Javascript file that contains our code
Build the project and double click bin\Debug\Spreadsheet.html to open it in a web browser. You should see an alert as soon as the file is loaded. If you don't see the alert, you should look at the debugger/console for any error messages. The process of debugging script# projects entails debugging the generated HTML/Javascript file in the browser.