diff --git a/src/ICSharpCore/Script/InteractiveScriptEngine.cs b/src/ICSharpCore/Script/InteractiveScriptEngine.cs index 1bc17b1..a8d66a5 100644 --- a/src/ICSharpCore/Script/InteractiveScriptEngine.cs +++ b/src/ICSharpCore/Script/InteractiveScriptEngine.cs @@ -37,6 +37,8 @@ public class InteractiveScriptEngine private string _currentDirectory; + private string[] _references; + public InteractiveScriptEngine(string currentDir, ILogger logger) { _currentDirectory = currentDir; @@ -44,6 +46,13 @@ public InteractiveScriptEngine(string currentDir, ILogger logger) _scriptOptions = CreateScriptOptions(); + var referencesFile = Path.Combine(Directory.GetCurrentDirectory(), "refs.txt"); + + if (File.Exists(referencesFile)) + { + _references = File.ReadAllLines(referencesFile, Encoding.UTF8); + } + _runtimeDependencyResolver = new RuntimeDependencyResolver((t) => (level, m, e) => { logger.Log(MapLogLevel(level), m, e); @@ -85,6 +94,15 @@ public async Task ExecuteAsync(string statement) "using static ICSharpCore.Primitives.DisplayDataEmitter;" }; + var refsFromFile = string.Empty; + + var references = _references; + + if (references != null && references.Any()) + { + usingStatements = references.Union(usingStatements).ToArray(); + } + _scriptState = await CSharpScript.RunAsync(string.Join("\r\n", usingStatements), _scriptOptions, globals: _globals); _scriptState = await _scriptState.ContinueWithAsync(statement, _scriptOptions); }