public object Execute(IScriptExecutor repl, object[] args) { if (args == null || args.Length == 0) { return null; } string version = null; var allowPre = false; if (args.Length >= 2) { version = args[1].ToString(); } allowPre = args.Length >= 3 && args[2].ToString().ToUpperInvariant() == "PRE"; _logger.InfoFormat("Installing {0}", args[0]); _installationProvider.Initialize(); var packageRef = new PackageReference( args[0].ToString(), new FrameworkName(".NETFramework,Version=v4.0"), version); _packageInstaller.InstallPackages(new[] { packageRef }, allowPre); _packageAssemblyResolver.SavePackages(); var dlls = _packageAssemblyResolver.GetAssemblyNames(repl.FileSystem.CurrentDirectory) .Except(repl.References.PathReferences).ToArray(); if(repl is IReplExecutor) ((IReplExecutor)repl).AddReferencesAndNotify(dlls); else repl.AddReferences(dlls); foreach (var dll in dlls) { _logger.InfoFormat("Added reference to {0}", dll); } return null; }
private object HandleReplCommand(string command, object[] args) { if(string.IsNullOrWhiteSpace(command)) return "The REPL command was empty."; command = command.ToLower(); if (command == "help") { return "Available commands are: " + Environment.NewLine + " :help - displays this information" + Environment.NewLine + " :clear - clears the REPL" + Environment.NewLine + " :install <package name> - installs a NuGet package"; } if (command == "clear") { repl.Clear(); return null; } if (command == "install") { if (args == null || args.Length == 0) return null; string version = null; var allowPre = false; if (args.Length >= 2) { version = args[1].ToString(); if (args.Length == 3) { allowPre = true; } } Logger.InfoFormat("Installing {0}", args[0]); var packageRef = new PackageReference(args[0].ToString(), new FrameworkName(".NETFramework,Version=v4.0"), version); packageInstaller.InstallPackages(new[] { packageRef }, allowPre); resolver.SavePackages(); var dlls = resolver.GetAssemblyNames(FileSystem.CurrentDirectory).Except(References.PathReferences).ToArray(); AddReferencesAndNotify(dlls); foreach (var dll in dlls) { Logger.InfoFormat("Added reference to {0}", dll); } return null; } return "Unknown REPL command: "+command; }