public Script Build(string cSharpScript, ScriptSettings settings, PluginRepository pluginRepo) { var ruriLib = Assembly.GetAssembly(typeof(ScriptBuilder)); var plugins = pluginRepo != null?pluginRepo.GetPlugins() : Array.Empty <Assembly>(); var script = CSharpScript.Create( code: preScript.ToString() + cSharpScript + postScript.ToString(), options: ScriptOptions.Default .WithReferences(new Assembly[] { ruriLib }.Concat(plugins)) .WithImports(GetImports(settings)), globalsType: typeof(ScriptGlobals)); // Add references from RuriLib var ruriLibReferences = ruriLib.GetReferencedAssemblies(); script.Options.AddReferences(AppDomain.CurrentDomain.GetAssemblies() .Where(a => ruriLibReferences.Any(r => r.FullName == a.FullName))); // Add references from plugins var pluginReferences = plugins.SelectMany(p => p.GetReferencedAssemblies()); script.Options.AddReferences(AppDomain.CurrentDomain.GetAssemblies() .Where(a => pluginReferences.Any(p => p.FullName == a.FullName))); return(script); }