我可以将VS2010中的IronRuby项目编译成DLL / exe文件吗?

时间:2010-11-16 04:02:28

标签: compiler-construction ironruby

使用IronRuby v1.1.x在VS2010中创建IronRuby项目之后,我通过导入几乎可以使用.NET库。但实际上无法将ironruby编译成exe / DLL。 我看到了构建选项,但无法从IronRuby项目构建任何exe或DLL。请帮忙!

3 个答案:

答案 0 :(得分:5)

有一个很棒的IronRuby gem将IronRuby文件打包成Windows可执行文件。

https://github.com/kumaryu/irpack

使用:

igem install irpack
irpack -o Program.exe Program.rb

答案 1 :(得分:4)

您无法将IronRuby类编译为.NET程序集,然后从另一个程序集访问它们。

Preet是对的,你可以得到的最近的就是将你的IronRuby脚本嵌入(比方说)一个C#程序集中。从C#侧可以实例化您的Ruby类。所以给出以下Ruby类:

class HelloWorld
  def say_hello
    puts 'Hello'
  end
end

您可以从资源文件加载它并从C#:

运行它
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting.Runtime;
using IronRuby;

var runtime = IronRuby.Ruby.CreateRuntime();
var engine = runtime.GetEngine("ruby");

var assembly = Assembly.GetExecutingAssembly();
var stream = assembly.GetManifestResourceStream("PathToResource.test.rb");
string code = new StreamReader(stream).ReadToEnd();

var scope = engine.CreateScope();
engine.Execute(code, scope);

dynamic helloWorldClass = engine.Runtime.Globals.GetVariable("HelloWorld");
dynamic ironRubyObject = engine.Operations.CreateInstance(helloWorldClass);
ironRubyObject.say_hello();

答案 2 :(得分:0)

由于Iron Ruby只是基于DLR的代码。您应该能够将代码添加到任何程序集的资源中。最终你需要一个bootstrap来加载代码。这很可能是一种CLR语言。

相关问题