emwe
emwe

Reputation: 45

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#)

Upvotes: 2

Views: 1045

Answers (2)

angel colmenares
angel colmenares

Reputation: 16

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

Upvotes: 0

nino.porcino
nino.porcino

Reputation: 1183

I tried your example and it produces the following:

Main.cs(9,13): error CS0103: The name `Console' does not exist in the current context

which is correct considering that Saltarelle's System namespace does not have a Console type. I don't know why it gives you the unhandled exception, what version are you using?

Saltarelle is an external compiler which does not depend on Mono or Visual Studio, although you can configure your IDE to call it when compiling your project.

Upvotes: 1

Related Questions