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

发布于 2024-10-03 08:50:52 字数 142 浏览 10 评论 0原文

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

After created IronRuby project in VS2010 by using IronRuby v1.1.x, I was able to use almost .NET library by importing them. But can't actually compile ironruby into exe/DLL.
I see the build option but can't build any exe or DLL from IronRuby project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猛虎独行 2024-10-10 08:50:52

有一个很棒的 IronRuby gem,可以将 IronRuby 文件打包到 Windows 可执行文件中。

https://github.com/kumaryu/irpack

使用:

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

There's a great IronRuby gem that packages IronRuby files into a Windows executable.

https://github.com/kumaryu/irpack

To use:

igem install irpack
irpack -o Program.exe Program.rb
[旋木] 2024-10-10 08:50:52

您无法将 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();

You can't compile your IronRuby classes into a .NET assembly and then access them from another assembly.

Preet is right that the nearest you can get is to embed your IronRuby scripts in (say) a C# assembly. From the C# side it would then be possible to instantiate your Ruby classes. So given the following Ruby class:

class HelloWorld
  def say_hello
    puts 'Hello'
  end
end

You could load this from a resource file and run it from 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();
如痴如狂 2024-10-10 08:50:52

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

Since Iron Ruby is simply DLR based code. You should be able to add the code into a resource of any assembly. Ultimately you'll need a bootstrap to load the code. That will most likely be a CLR language.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文