如何在 Mono Develop(Ubuntu、Linux)中将 Saltarelle C# 设置为 JavaScript 编译器

问题描述 投票:0回答:2

我尝试在 Mono 中的默认控制台项目上使用 Saltarelle C# 编译器

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

但是当我尝试使用终端命令编译它时

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

出现此错误:

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'.

我做错了什么?有没有人成功使用 Saltarelle (或任何其他 C# 到 Javascript 编译器,如

Script#)设置 Mono-Develop

javascript c# linux monodevelop
2个回答
1
投票
我尝试了你的示例,它产生以下结果:

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

考虑到 Saltarelle 的

System

 命名空间没有 
Console
 类型,这是正确的。我不知道为什么它会给你未处理的异常,你使用什么版本?

Saltarelle 是一个外部编译器,不依赖于 Mono 或 Visual Studio,尽管您可以配置 IDE 在编译项目时调用它。


0
投票
你必须:

    消除 MS System.dll 引用(并使用 System;因此没有 Console.WriteLine!);
  1. 添加对 saltarelle mscorlib.dll 的引用,并可选择添加对 Script.Web.dll 的引用
  2. 注明运行时间:
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

© www.soinside.com 2019 - 2024. All rights reserved.