javascriptc#linuxmonodevelop

How to setup Saltarelle C# to JavaScript Compiler in Mono Develop (Ubuntu, Linux)


I tried to use the Saltarelle C# Compiler on a default Console Project in Mono

using System;

namespace SaltarelleConsoleTest
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.WriteLine ("Hello World!");
        }
    }
}

but when I try to compile it with the terminal command

mono lib/Saltarelle.Compiler/tools/sc.exe -reference:lib/Saltarelle.Runtime/tools/Assemblies/mscorlib.dll Main.cs -outscript:bin/main.js

this error occurs:

Unhandled Exception: System.TypeLoadException: Could not load type 'Saltarelle.Compiler.Program' from assembly 'sc, Version=1.5.0.0, Culture=neutral, PublicKeyToken=a4048e8fcc593f14'.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'Saltarelle.Compiler.Program' from assembly 'sc, Version=1.5.0.0, Culture=neutral, PublicKeyToken=a4048e8fcc593f14'.

What I am doing wrong? Has anyone successfully set up Mono-Develop with Saltarelle (or any other C# to Javascript Compiler like Script#)


Solution

  • you must:

    1. Eliminate MS System.dll reference ( and using System; So no Console.WriteLine !);
    2. add reference to saltarelle mscorlib.dll and optionally to Script.Web.dll
    3. indicate the runtime:

    mono --runtime=v4.0.30319 lib/Saltarelle.Compiler/tools/sc.exe -reference:lib/Saltarelle.Runtime/tools/Assemblies/mscorlib.dll Main.cs -outscript:bin/main.js