Search code examples
c#rubyironruby

IronRuby, How make ruby file executed from the regular C# project directory rather than bin\debug folder?


Finding a proper title for my question wasn't easy, please feel free to re-edit if needed. Now:

In the following code the program crashes as soon as it runs.

using System;
using IronRuby;
using IronRuby.Runtime;

namespace IronRuby_Test_03
{
    class Program
    {
        public static void Main(string[] args)
        {
            var engine = Ruby.CreateEngine();
            engine.ExecuteFile("Ruby_Test.rb");
            dynamic ruby = engine.Runtime.Globals;
        }
    }
} 

According to the debugger the reason is quite obvious,

"Could not find file 'C:\Documents and Settings\DEVELOPER\Desktop\IronRuby_Test_03\lkhhytu\bin\Debug\Ruby_Test.rb"

. The program expects the file to be in the bin\debug directory, and of course when I move the file there the program runs properly.

However it's not fun to have project files located in that bin\debug folder and it makes management a bit awkward. So my question now, is there a way to make the program runs normally and have 'Ruby_Test.rb' in the main project directory among all other regular project files?


Solution

  • That's the intended behavior. Go to the project properties under "Debug" and set the "Working Directory" to be your project dir.

    Project Properties for a CS Project (Visual Studio 2012 Express)

    You'll have to do this once for every Configuration (usually "Debug" and "Release").