我可以将VS2010中的IronRuby项目编译成DLL / exe文件吗? [英] Can I compile IronRuby project in VS2010 into DLL/exe file?
问题描述
在VS2010中通过使用IronRuby v1.1.x创建IronRuby项目后,我能够通过导入使用几乎.NET库。但是实际上不能将ironruby编译成exe / DLL。
我看到build选项,但无法构建任何exe或DLL从IronRuby项目。请帮助!
无法将IronRuby类编译成.NET程序集,然后从另一个程序集访问它们。 / p>
Preet是正确的,最近你可以得到的是嵌入你的IronRuby脚本在(说)一个C#程序集。从C#方面,然后就可以实例化你的Ruby类。所以给定下面的Ruby类:
class HelloWorld
def say_hello
puts'Hello'
end
end
文件并从C#运行它:
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting.Runtime;
使用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();
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. Please help !
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();
这篇关于我可以将VS2010中的IronRuby项目编译成DLL / exe文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!