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 !
Asked
Active
Viewed 2,184 times
4
-
Duplicate of http://stackoverflow.com/questions/561509/how-do-i-create-a-net-assembly-in-ironpython-and-call-it-from-c . (Not a strict duplicate, but the answer is the same.) – cdhowie Nov 16 '10 at 04:12
-
But still no clue on how to compile this into .NET assembly ? And this time is in IronRuby not IronPython. – Little Jack Nov 16 '10 at 04:22
-
That's because it's not possible per se. And it doesn't matter; you can't do this because both IronRuby and IronPython use the DLR. The actual language doesn't matter at all. – cdhowie Nov 16 '10 at 06:10
3 Answers
5
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

Roy Tinker
- 10,044
- 4
- 41
- 58
4
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();
-
1It would be great if Visual Studio could compile IronRuby code to an EXE. – Roy Tinker Oct 07 '11 at 22:32
0
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.

Preet Sangha
- 64,563
- 18
- 145
- 216
-
Does that mean I must get IronRuby source code and linking it with my Ruby project and compile it using .NET ? – Little Jack Nov 16 '10 at 04:19