This project has moved. For the latest updates, please go here.

Setup a project

Two types of project are possible :
  • A regular web application, with one or more html or aspx (or anything else) pages. The C# code will be referenced in the pages in one ore more JavaScript extracts. So you will "export" one or more types to be used in regular JavaScript in your pages.
  • A pure-script web application, with a single code entry point. Whole page will be generated by script.

Visual Studio

A template for each kind of project is provided. You can access them in "New Project", in the "C# / Web" section.

If you have an existing project, see "MsBuild" section to modify your csproj.

MsBuild

In all cases, add a reference to assembly "NetWebScript.Core" (from GAC).

Open your project file (usually a csproj), add the following lines :

    <Import Project="$(NwsAppPath)bin\NetWebScript.targets" />
    <Target Name="AfterBuild" DependsOnTargets="NwsCompile">


By default, in "Debug" target, code will instrumented and will try to attach debugger. In "Release" target, code will be in the compact form.

To override this behavior, you can set the following properties in the "PropertyGroup" of each target.
  • NwsDebuggable : true or false, if true Instrument code for debugger, and try to attach debugger instance
  • NwsPrettyPrint : true of false, if true generate JavaScript will be "human readable"

Example :
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugNoDebugger|AnyCPU' ">
    ...
    <NwsDebuggable>false</NwsDebuggable>
    <NwsPrettyPrint>true</NwsPrettyPrint>
</PropertyGroup>


At compilation, a JavaScript file with the name of the project will be gerenerated at project root.
A file with JQuery will be also added.

To allow debugger to be started with web application, change "ProjectTypeGuids" to the following value (you should simply add the first guid):
<ProjectTypeGuids>{05A87499-F343-4FCA-BCD0-B90EF6FC4558};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

Regular web application

In your pages, add following lines in the "head" :
    <script src="jquery-1.6.4.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="[project name].js" type="text/javascript" charset="utf-8"></script>

Pure-Script web application

Create a class in your project that implements "IScriptPage".

In the project file, in the first "PropertyGroup" section, add a property "NwsEntryPointClass" with the previous class fullname.

<PropertyGroup>
    ...
    <NwsEntryPointClass>MyProject.MyEntryPointClass</NwsEntryPointClass>
</PropertyGroup>


At compilation, an html file with the name of the project will be gerenerated at project root.

Debug version of NetWebScript

If you use your own compiled version of NetWebScript, you should use the command line interface and not the MsBuild task. See contribute for more informations.

Last edited Jan 19, 2012 at 10:18 PM by jetelain, version 2

Comments

No comments yet.