roslynpad

Reference one RoslynPad script from another


What I'd like to do is reference one script from another.

One way to make this happen might be using assemblies. RoslynPad allows compiling a script into an assembly. Here is what I have tried so far.

Script A, which is compiled to SOME_PATH\thing.dll

    class Thing
    {
        public string Name { get; set; }
    }

Script B

    #r "SOME_PATH\thing.dll"

    using static Program;

    var t = new Thing();
    t.Name = "TEST";
    t.Name.Dump();

This gives the error "The type or namespace 'Thing' could not be found..." so I tried the following.

    #r "SOME_PATH\thing.dll"

    var t = new Program.Thing();
    t.Name = "TEST";
    t.Name.Dump();

This gave the following error "The type name 'Thing' does not exist in the type 'Program'".

Is there a way to "Compile and Save assembly" and then reference it from another script? Or, is there a more direct way to cross reference between scripts?


Solution

  • What you're looking for is the #load directive:

    #load "Path\To\ScriptA.csx"
    
    var t = new Thing();
    

    You can read more about the C# script variant in the Roslyn wiki. Note that not everything there is relevant to RoslynPad, which unlike the C# Interactive window, is not a REPL.