title: How to load referenced script libraries from a Roslyn script file?
body: <p>I figured out I cannot load one script library from another easily:</p>
  
  <p>module.csx</p>
  
  <pre><code>string SomeFunction() {
     return "something";
  }
  </code></pre>
  
  <p>script.csx</p>
  
  <pre><code>ExecuteFile("module.csx");
  SomeFunction() &lt;-- causes compile error "SomeFunction" does not exist
  </code></pre>
  
  <p>This is because the compiler does not know of module.csx at the time it compiles script.csx afaiu. I can add another script to load the two files from that one, and that will work. However thats not that pretty.</p>
  
  <p>Instead I like to make my scripthost check for a special syntax "load module" within my scripts, and execute those modules before actual script execution. </p>
  
  <p>script.csx</p>
  
  <pre><code>// load "module.csx"
  SomeFunction()
  </code></pre>
  
  <p>Now, with some basic string handling, I can figure out which modules to load (lines that contains // load ...) and load that files (gist here <a href="https://gist.github.com/4147064" rel="nofollow">https://gist.github.com/4147064</a>):</p>
  
  <pre><code>foreach(var module in scriptModules) {
     session.ExecuteFile(module);
  }
  return session.Execute(script)
  </code></pre>
  
  <p>But - since we're talking Roslyn, there should be some nice way to parse the script for the syntax I'm looking for, right?</p>
  
  <p>And it might even exist a way to handle module libraries of code?</p>