为什么“需要”?通过 C# 程序加载 (iron)ruby 脚本时语句失败?
IronRuby 和 VS2010 菜鸟问题:
我正在尝试做一个峰值来测试 C# 项目和现有 RubyGem 之间互操作的可行性,而不是在 .net 中重新发明那个特定的轮子。我已经下载并安装了 IronRuby 和 RubyGems 包,以及我最终想要使用的 gem。
运行 .rb 文件或在 iirb Ruby 控制台中工作没有问题。我可以加载 RubyGems 包和 gem 本身并使用它,因此,至少对于该用例,我的环境设置正确。
但是,当我尝试在 C# (4.0) 控制台应用程序中执行相同的操作时,它会抱怨第一行:
require 'RubyGems'
出现错误:
no such file to load -- rubygems
我的控制台应用程序如下所示:
using System;
using IronRuby;
namespace RubyInteropSpike
{
class Program
{
static void Main(string[] args)
{
var runtime = Ruby.CreateRuntime();
var scope = runtime.ExecuteFile("test.rb");
Console.ReadKey();
}
}
}
删除依赖项并仅执行一些基本的自我操作-包含的 Ruby 东西工作正常,但包含任何类型的“requires”语句似乎会导致它失败。
我希望在创建 ruby 运行时时只需要传递一些附加信息(路径等),并且真的希望这不是某种限制,因为这会让我感到难过。
IronRuby and VS2010 noob question:
I'm trying to do a spike to test the feasibility of interop between a C# project and an existing RubyGem rather than re-invent that particular wheel in .net. I've downloaded and installed IronRuby and the RubyGems package, as well as the gem I'd ultimately like to use.
Running .rb files or working in the iirb Ruby console is without problems. I can load the both the RubyGems package, and the gem itself and use it, so, at least for that use case, my environment is set up correctly.
However, when I try to do the same sort of thing from within a C# (4.0) console app, it complains about the very first line:
require 'RubyGems'
With the error:
no such file to load -- rubygems
My Console app looks like this:
using System;
using IronRuby;
namespace RubyInteropSpike
{
class Program
{
static void Main(string[] args)
{
var runtime = Ruby.CreateRuntime();
var scope = runtime.ExecuteFile("test.rb");
Console.ReadKey();
}
}
}
Removing the dependencies and just doing some basic self-contained Ruby stuff works fine, but including any kind of 'requires' statement seems to cause it to fail.
I'm hoping that I just need to pass some additional information (paths, etc) to the ruby runtime when I create it, and really hoping that this isn't some kind of limitation, because that would make me sad.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的回答:是的,这将按照您想要的方式工作。
您需要使用引擎的 SetSearchPaths 方法来执行您想要的操作。
更完整的示例
(假设您将 IronRuby 加载到 C:\IronRubyRC2 作为根安装目录)
Short answer: Yes, this will work how you want it to.
You need to use the engine's SetSearchPaths method to do what you wish.
A more complete example
(Assumes you loaded your IronRuby to C:\IronRubyRC2 as the root install dir)