diff --git a/src/.vscode/tasks.json b/src/.vscode/tasks.json index 4046a0bb..bb57ccb0 100644 --- a/src/.vscode/tasks.json +++ b/src/.vscode/tasks.json @@ -6,7 +6,7 @@ "command": "dotnet", "args": [ "build", - "${workspaceRoot}/Dotnet.Script/Dotnet.Script.csproj", + "${workspaceRoot}/../Dotnet.Script.sln", "/property:GenerateFullPaths=true" ], "group": { diff --git a/src/Dotnet.Script.Core/Commands/ExecuteCodeCommand.cs b/src/Dotnet.Script.Core/Commands/ExecuteCodeCommand.cs index 688540b0..eeae0acd 100644 --- a/src/Dotnet.Script.Core/Commands/ExecuteCodeCommand.cs +++ b/src/Dotnet.Script.Core/Commands/ExecuteCodeCommand.cs @@ -22,14 +22,14 @@ public async Task Execute(ExecuteCodeCommandOptions options) { var sourceText = SourceText.From(options.Code); var context = new ScriptContext(sourceText, options.WorkingDirectory ?? Directory.GetCurrentDirectory(), options.Arguments, null, options.OptimizationLevel, ScriptMode.Eval, options.PackageSources); - var compiler = GetScriptCompiler(!options.NoCache, _logFactory); + var compiler = GetScriptCompiler(!options.NoCache, !options.NoNugetCache, _logFactory); var runner = new ScriptRunner(compiler, _logFactory, _scriptConsole); return await runner.Execute(context); } - private static ScriptCompiler GetScriptCompiler(bool useRestoreCache, LogFactory logFactory) + private static ScriptCompiler GetScriptCompiler(bool useRestoreCache, bool useNugetCache, LogFactory logFactory) { - var compiler = new ScriptCompiler(logFactory, useRestoreCache); + var compiler = new ScriptCompiler(logFactory, useRestoreCache, useNugetCache); return compiler; } } diff --git a/src/Dotnet.Script.Core/Commands/ExecuteCodeCommandOptions.cs b/src/Dotnet.Script.Core/Commands/ExecuteCodeCommandOptions.cs index b1bdf40b..bbdd7716 100644 --- a/src/Dotnet.Script.Core/Commands/ExecuteCodeCommandOptions.cs +++ b/src/Dotnet.Script.Core/Commands/ExecuteCodeCommandOptions.cs @@ -4,13 +4,14 @@ namespace Dotnet.Script.Core.Commands { public class ExecuteCodeCommandOptions { - public ExecuteCodeCommandOptions(string code, string workingDirectory, string[] arguments, OptimizationLevel optimizationLevel, bool noCache, string[] packageSources) + public ExecuteCodeCommandOptions(string code, string workingDirectory, string[] arguments, OptimizationLevel optimizationLevel, bool noCache, bool noNugetCache, string[] packageSources) { Code = code; WorkingDirectory = workingDirectory; Arguments = arguments; OptimizationLevel = optimizationLevel; NoCache = noCache; + NoNugetCache = noNugetCache; PackageSources = packageSources; } @@ -19,6 +20,7 @@ public ExecuteCodeCommandOptions(string code, string workingDirectory, string[] public string[] Arguments { get; } public OptimizationLevel OptimizationLevel { get; } public bool NoCache { get; } + public bool NoNugetCache { get; } public string[] PackageSources { get; } } } \ No newline at end of file diff --git a/src/Dotnet.Script.Core/Commands/ExecuteInteractiveCommand.cs b/src/Dotnet.Script.Core/Commands/ExecuteInteractiveCommand.cs index 17d4f3cf..296d99e5 100644 --- a/src/Dotnet.Script.Core/Commands/ExecuteInteractiveCommand.cs +++ b/src/Dotnet.Script.Core/Commands/ExecuteInteractiveCommand.cs @@ -18,7 +18,7 @@ public ExecuteInteractiveCommand(ScriptConsole scriptConsole, LogFactory logFact public async Task Execute(ExecuteInteractiveCommandOptions options) { - var compiler = new ScriptCompiler(_logFactory, useRestoreCache: false); + var compiler = new ScriptCompiler(_logFactory, useRestoreCache: false, useNugetCache: true); var runner = new InteractiveRunner(compiler, _logFactory, _scriptConsole, options.PackageSources); if (options.ScriptFile == null) diff --git a/src/Dotnet.Script.Core/Commands/ExecuteLibraryCommand.cs b/src/Dotnet.Script.Core/Commands/ExecuteLibraryCommand.cs index d7350e82..73b468ca 100644 --- a/src/Dotnet.Script.Core/Commands/ExecuteLibraryCommand.cs +++ b/src/Dotnet.Script.Core/Commands/ExecuteLibraryCommand.cs @@ -25,15 +25,15 @@ public async Task Execute(ExecuteLibraryCommandOptions options } var absoluteFilePath = options.LibraryPath.GetRootedPath(); - var compiler = GetScriptCompiler(!options.NoCache, _logFactory); + var compiler = GetScriptCompiler(!options.NoCache, !options.NoNugetCache, _logFactory); var runner = new ScriptRunner(compiler, _logFactory, _scriptConsole); var result = await runner.Execute(absoluteFilePath, options.Arguments); return result; } - private static ScriptCompiler GetScriptCompiler(bool useRestoreCache, LogFactory logFactory) + private static ScriptCompiler GetScriptCompiler(bool useRestoreCache, bool useNugetCache, LogFactory logFactory) { - var compiler = new ScriptCompiler(logFactory, useRestoreCache); + var compiler = new ScriptCompiler(logFactory, useRestoreCache, useNugetCache); return compiler; } } diff --git a/src/Dotnet.Script.Core/Commands/ExecuteLibraryCommandOptions.cs b/src/Dotnet.Script.Core/Commands/ExecuteLibraryCommandOptions.cs index 2c0f4796..7f73384e 100644 --- a/src/Dotnet.Script.Core/Commands/ExecuteLibraryCommandOptions.cs +++ b/src/Dotnet.Script.Core/Commands/ExecuteLibraryCommandOptions.cs @@ -2,15 +2,17 @@ namespace Dotnet.Script.Core.Commands { public class ExecuteLibraryCommandOptions { - public ExecuteLibraryCommandOptions(string libraryPath, string[] arguments, bool noCache) + public ExecuteLibraryCommandOptions(string libraryPath, string[] arguments, bool noCache, bool noNugetCache) { LibraryPath = libraryPath; Arguments = arguments; NoCache = noCache; + NoNugetCache = noNugetCache; } public string LibraryPath { get; } public string[] Arguments { get; } public bool NoCache { get; } + public bool NoNugetCache { get; } } } \ No newline at end of file diff --git a/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs b/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs index 6bf3809c..fc6bce3e 100644 --- a/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs +++ b/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs @@ -32,14 +32,14 @@ public async Task Run(ExecuteScriptCommandOptions optio } var pathToLibrary = GetLibrary(options); - return await ExecuteLibrary(pathToLibrary, options.Arguments, options.NoCache); + return await ExecuteLibrary(pathToLibrary, options.Arguments, options.NoCache, options.NoNugetCache); } private async Task DownloadAndRunCode(ExecuteScriptCommandOptions executeOptions) { var downloader = new ScriptDownloader(); var code = await downloader.Download(executeOptions.File.Path); - var options = new ExecuteCodeCommandOptions(code, Directory.GetCurrentDirectory(), executeOptions.Arguments, executeOptions.OptimizationLevel, executeOptions.NoCache, executeOptions.PackageSources); + var options = new ExecuteCodeCommandOptions(code, Directory.GetCurrentDirectory(), executeOptions.Arguments, executeOptions.OptimizationLevel, executeOptions.NoCache, executeOptions.NoNugetCache, executeOptions.PackageSources); return await new ExecuteCodeCommand(_scriptConsole, _logFactory).Execute(options); } @@ -57,7 +57,7 @@ private string GetLibrary(ExecuteScriptCommandOptions executeOptions) return pathToLibrary; } - var options = new PublishCommandOptions(executeOptions.File, executionCacheFolder, "script", PublishType.Library, executeOptions.OptimizationLevel, executeOptions.PackageSources, null, executeOptions.NoCache); + var options = new PublishCommandOptions(executeOptions.File, executionCacheFolder, "script", PublishType.Library, executeOptions.OptimizationLevel, executeOptions.PackageSources, null, executeOptions.NoCache, executeOptions.NoNugetCache); new PublishCommand(_scriptConsole, _logFactory).Execute(options); if (hash != null) { @@ -125,9 +125,9 @@ public bool TryGetHash(string cacheFolder, out string hash) return true; } - private async Task ExecuteLibrary(string pathToLibrary, string[] arguments, bool noCache) + private async Task ExecuteLibrary(string pathToLibrary, string[] arguments, bool noCache, bool noNugetCache) { - var options = new ExecuteLibraryCommandOptions(pathToLibrary, arguments, noCache); + var options = new ExecuteLibraryCommandOptions(pathToLibrary, arguments, noCache, noNugetCache); return await new ExecuteLibraryCommand(_scriptConsole, _logFactory).Execute(options); } } diff --git a/src/Dotnet.Script.Core/Commands/ExecuteScriptCommandOptions.cs b/src/Dotnet.Script.Core/Commands/ExecuteScriptCommandOptions.cs index 656cb74d..d45db136 100644 --- a/src/Dotnet.Script.Core/Commands/ExecuteScriptCommandOptions.cs +++ b/src/Dotnet.Script.Core/Commands/ExecuteScriptCommandOptions.cs @@ -4,7 +4,7 @@ namespace Dotnet.Script.Core.Commands { public class ExecuteScriptCommandOptions { - public ExecuteScriptCommandOptions(ScriptFile file, string[] arguments, OptimizationLevel optimizationLevel, string[] packageSources, bool isInteractive ,bool noCache) + public ExecuteScriptCommandOptions(ScriptFile file, string[] arguments, OptimizationLevel optimizationLevel, string[] packageSources, bool isInteractive, bool noCache, bool noNugetCache) { File = file; Arguments = arguments; @@ -12,6 +12,7 @@ public ExecuteScriptCommandOptions(ScriptFile file, string[] arguments, Optimiza PackageSources = packageSources; IsInteractive = isInteractive; NoCache = noCache; + NoNugetCache = noNugetCache; } public ScriptFile File { get; } @@ -20,5 +21,6 @@ public ExecuteScriptCommandOptions(ScriptFile file, string[] arguments, Optimiza public string[] PackageSources { get; } public bool IsInteractive { get; } public bool NoCache { get; } + public bool NoNugetCache { get; } } } \ No newline at end of file diff --git a/src/Dotnet.Script.Core/Commands/PublishCommand.cs b/src/Dotnet.Script.Core/Commands/PublishCommand.cs index 684911c0..9d9ced36 100644 --- a/src/Dotnet.Script.Core/Commands/PublishCommand.cs +++ b/src/Dotnet.Script.Core/Commands/PublishCommand.cs @@ -28,7 +28,7 @@ public void Execute(PublishCommandOptions options) (options.PublishType == PublishType.Library ? Path.Combine(Path.GetDirectoryName(absoluteFilePath), "publish") : Path.Combine(Path.GetDirectoryName(absoluteFilePath), "publish", options.RuntimeIdentifier)); var absolutePublishDirectory = publishDirectory.GetRootedPath(); - var compiler = GetScriptCompiler(!options.NoCache, _logFactory); + var compiler = GetScriptCompiler(!options.NoCache, !options.NoNugetCache, _logFactory); var scriptEmitter = new ScriptEmitter(_scriptConsole, compiler); var publisher = new ScriptPublisher(_logFactory, scriptEmitter); var code = absoluteFilePath.ToSourceText(); @@ -44,10 +44,10 @@ public void Execute(PublishCommandOptions options) } } - private static ScriptCompiler GetScriptCompiler(bool useRestoreCache, LogFactory logFactory) + private static ScriptCompiler GetScriptCompiler(bool useRestoreCache, bool useNuGetCache, LogFactory logFactory) { - var compiler = new ScriptCompiler(logFactory, useRestoreCache); + var compiler = new ScriptCompiler(logFactory, useRestoreCache, useNuGetCache); return compiler; } } diff --git a/src/Dotnet.Script.Core/Commands/PublishCommandOptions.cs b/src/Dotnet.Script.Core/Commands/PublishCommandOptions.cs index a82fa295..bf2d6d05 100644 --- a/src/Dotnet.Script.Core/Commands/PublishCommandOptions.cs +++ b/src/Dotnet.Script.Core/Commands/PublishCommandOptions.cs @@ -5,7 +5,7 @@ namespace Dotnet.Script.Core.Commands { public class PublishCommandOptions { - public PublishCommandOptions(ScriptFile file, string outputDirectory, string libraryName, PublishType publishType, OptimizationLevel optimizationLevel, string[] packageSources, string runtimeIdentifier, bool noCache) + public PublishCommandOptions(ScriptFile file, string outputDirectory, string libraryName, PublishType publishType, OptimizationLevel optimizationLevel, string[] packageSources, string runtimeIdentifier, bool noCache, bool noNugetCache) { File = file; OutputDirectory = outputDirectory; @@ -15,6 +15,7 @@ public PublishCommandOptions(ScriptFile file, string outputDirectory, string lib PackageSources = packageSources; RuntimeIdentifier = runtimeIdentifier ?? ScriptEnvironment.Default.RuntimeIdentifier; NoCache = noCache; + NoNugetCache = noNugetCache; } public ScriptFile File { get; } @@ -25,6 +26,7 @@ public PublishCommandOptions(ScriptFile file, string outputDirectory, string lib public string[] PackageSources { get; } public string RuntimeIdentifier { get; } public bool NoCache { get; } + public bool NoNugetCache { get; } } public enum PublishType diff --git a/src/Dotnet.Script.Core/ScriptCompiler.cs b/src/Dotnet.Script.Core/ScriptCompiler.cs index 994cb39f..05ed7158 100644 --- a/src/Dotnet.Script.Core/ScriptCompiler.cs +++ b/src/Dotnet.Script.Core/ScriptCompiler.cs @@ -59,8 +59,8 @@ static ScriptCompiler() public RuntimeDependencyResolver RuntimeDependencyResolver { get; } - public ScriptCompiler(LogFactory logFactory, bool useRestoreCache) - : this(logFactory, new RuntimeDependencyResolver(logFactory, useRestoreCache)) + public ScriptCompiler(LogFactory logFactory, bool useRestoreCache, bool useNugetCache) + : this(logFactory, new RuntimeDependencyResolver(logFactory, useRestoreCache, useNugetCache)) { } @@ -82,7 +82,7 @@ public virtual ScriptOptions CreateScriptOptions(ScriptContext context, IList rdt.Name, rdt => rdt.Scripts); var opts = ScriptOptions.Default.AddImports(ImportedNamespaces) - .WithSourceResolver(new NuGetSourceReferenceResolver(new SourceFileResolver(ImmutableArray.Empty, context.WorkingDirectory),scriptMap)) + .WithSourceResolver(new NuGetSourceReferenceResolver(new SourceFileResolver(ImmutableArray.Empty, context.WorkingDirectory), scriptMap)) .WithMetadataResolver(new NuGetMetadataReferenceResolver(ScriptMetadataResolver.Default.WithBaseDirectory(context.WorkingDirectory))) .WithEmitDebugInformation(true) .WithLanguageVersion(LanguageVersion.Preview) @@ -266,7 +266,7 @@ private Assembly MapUnresolvedAssemblyToRuntimeLibrary(IDictionary assemblyName.Version) { loadedAssemblyMap.TryGetValue(assemblyName.Name, out var loadedAssembly); - if(loadedAssembly != null) + if (loadedAssembly != null) { _logger.Trace($"Redirecting {assemblyName} to already loaded {loadedAssembly.GetName().Name}"); return loadedAssembly; diff --git a/src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs b/src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs index 8acf2981..0086191e 100644 --- a/src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs +++ b/src/Dotnet.Script.DependencyModel/Compilation/CompilationDependencyResolver.cs @@ -56,7 +56,7 @@ public IEnumerable GetDependencies(string targetDirectory private static IRestorer CreateRestorer(LogFactory logFactory) { var commandRunner = new CommandRunner(logFactory); - return new ProfiledRestorer(new DotnetRestorer(commandRunner, logFactory), logFactory); + return new ProfiledRestorer(new DotnetRestorer(commandRunner, logFactory, useNugetCache: true), logFactory); } } } \ No newline at end of file diff --git a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs index bfacf1ca..5a785dfe 100644 --- a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs +++ b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs @@ -11,12 +11,14 @@ namespace Dotnet.Script.DependencyModel.Context public class DotnetRestorer : IRestorer { private readonly CommandRunner _commandRunner; + private readonly bool _useNugetCache; private readonly Logger _logger; private readonly ScriptEnvironment _scriptEnvironment; - public DotnetRestorer(CommandRunner commandRunner, LogFactory logFactory) + public DotnetRestorer(CommandRunner commandRunner, LogFactory logFactory, bool useNugetCache) { _commandRunner = commandRunner; + _useNugetCache = useNugetCache; _logger = logFactory.CreateLogger(); _scriptEnvironment = ScriptEnvironment.Default; } @@ -28,10 +30,10 @@ public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources) var runtimeIdentifier = _scriptEnvironment.RuntimeIdentifier; var workingDirectory = Path.GetFullPath(Path.GetDirectoryName(projectFileInfo.Path)); - + string noCacheFlag = _useNugetCache ? string.Empty : "--no-cache"; _logger.Debug($"Restoring {projectFileInfo.Path} using the dotnet cli. RuntimeIdentifier : {runtimeIdentifier} NugetConfigFile: {projectFileInfo.NuGetConfigFile}"); - var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument} {configFileArgument}", workingDirectory); + var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" {noCacheFlag} -r {runtimeIdentifier} {packageSourcesArgument} {configFileArgument}", workingDirectory); if (exitcode != 0) { // We must throw here, otherwise we may incorrectly run with the old 'project.assets.json' diff --git a/src/Dotnet.Script.DependencyModel/Runtime/RuntimeDependencyResolver.cs b/src/Dotnet.Script.DependencyModel/Runtime/RuntimeDependencyResolver.cs index 7cc1c86e..24119be0 100644 --- a/src/Dotnet.Script.DependencyModel/Runtime/RuntimeDependencyResolver.cs +++ b/src/Dotnet.Script.DependencyModel/Runtime/RuntimeDependencyResolver.cs @@ -13,31 +13,33 @@ namespace Dotnet.Script.DependencyModel.Runtime public class RuntimeDependencyResolver { private readonly ScriptProjectProvider _scriptProjectProvider; + private readonly bool _useNugetCache; private readonly ScriptDependencyContextReader _dependencyContextReader; private readonly IRestorer _restorer; - public RuntimeDependencyResolver(ScriptProjectProvider scriptProjectProvider, LogFactory logFactory, bool useRestoreCache) + public RuntimeDependencyResolver(ScriptProjectProvider scriptProjectProvider, LogFactory logFactory, bool useRestoreCache, bool useNugetCache) { _scriptProjectProvider = scriptProjectProvider; + _useNugetCache = useNugetCache; _dependencyContextReader = new ScriptDependencyContextReader(logFactory); - _restorer = CreateRestorer(logFactory, useRestoreCache); + _restorer = CreateRestorer(logFactory, useRestoreCache, useNugetCache); } - public RuntimeDependencyResolver(LogFactory logFactory, bool useRestoreCache) : this(new ScriptProjectProvider(logFactory), logFactory, useRestoreCache) + public RuntimeDependencyResolver(LogFactory logFactory, bool useRestoreCache, bool useNugetCache) : this(new ScriptProjectProvider(logFactory), logFactory, useRestoreCache, useNugetCache) { } - private static IRestorer CreateRestorer(LogFactory logFactory, bool useRestoreCache) + private static IRestorer CreateRestorer(LogFactory logFactory, bool useRestoreCache, bool useNugetCache) { var commandRunner = new CommandRunner(logFactory); if (useRestoreCache) { - return new ProfiledRestorer(new CachedRestorer(new DotnetRestorer(commandRunner, logFactory), logFactory), logFactory); + return new ProfiledRestorer(new CachedRestorer(new DotnetRestorer(commandRunner, logFactory, useNugetCache), logFactory), logFactory); } else { - return new ProfiledRestorer(new DotnetRestorer(commandRunner, logFactory), logFactory); + return new ProfiledRestorer(new DotnetRestorer(commandRunner, logFactory, useNugetCache), logFactory); } } diff --git a/src/Dotnet.Script.Shared.Tests/InteractiveRunnerTestsBase.cs b/src/Dotnet.Script.Shared.Tests/InteractiveRunnerTestsBase.cs index f6a90d74..5be83516 100644 --- a/src/Dotnet.Script.Shared.Tests/InteractiveRunnerTestsBase.cs +++ b/src/Dotnet.Script.Shared.Tests/InteractiveRunnerTestsBase.cs @@ -39,7 +39,7 @@ private InteractiveTestContext GetRunner(params string[] commands) var logFactory = TestOutputHelper.CreateTestLogFactory(); - var compiler = new ScriptCompiler(logFactory, useRestoreCache: false); + var compiler = new ScriptCompiler(logFactory, useRestoreCache: false, useNugetCache: true); var runner = new InteractiveRunner(compiler, logFactory, console, Array.Empty()); return new InteractiveTestContext(console, runner); } diff --git a/src/Dotnet.Script.Tests/ScriptPackagesTests.cs b/src/Dotnet.Script.Tests/ScriptPackagesTests.cs index 043cfa64..04b74116 100644 --- a/src/Dotnet.Script.Tests/ScriptPackagesTests.cs +++ b/src/Dotnet.Script.Tests/ScriptPackagesTests.cs @@ -113,7 +113,7 @@ private static string GetFullPathToTestFixture(string path) private RuntimeDependencyResolver CreateRuntimeDependencyResolver() { - var resolver = new RuntimeDependencyResolver(TestOutputHelper.CreateTestLogFactory(), useRestoreCache: false); + var resolver = new RuntimeDependencyResolver(TestOutputHelper.CreateTestLogFactory(), useRestoreCache: false, useNugetCache: true); return resolver; } diff --git a/src/Dotnet.Script.Tests/ScriptRunnerTests.cs b/src/Dotnet.Script.Tests/ScriptRunnerTests.cs index 913ad33d..389f2376 100644 --- a/src/Dotnet.Script.Tests/ScriptRunnerTests.cs +++ b/src/Dotnet.Script.Tests/ScriptRunnerTests.cs @@ -23,7 +23,7 @@ public void ResolveAssembly_ReturnsNull_WhenRuntimeDepsMapDoesNotContainAssembly private ScriptRunner CreateScriptRunner() { var logFactory = TestOutputHelper.CreateTestLogFactory(); - var scriptCompiler = new ScriptCompiler(logFactory, false); + var scriptCompiler = new ScriptCompiler(logFactory, useRestoreCache:false, useNugetCache:true); return new ScriptRunner(scriptCompiler, logFactory, ScriptConsole.Default); } diff --git a/src/Dotnet.Script/Program.cs b/src/Dotnet.Script/Program.cs index 54b2c196..4a83e9f2 100644 --- a/src/Dotnet.Script/Program.cs +++ b/src/Dotnet.Script/Program.cs @@ -66,10 +66,11 @@ private static int Wain(string[] args) var debugMode = app.Option(DebugFlagShort + " | " + DebugFlagLong, "Enables debug output.", CommandOptionType.NoValue); var verbosity = app.Option("--verbosity", " Set the verbosity level of the command. Allowed values are t[trace], d[ebug], i[nfo], w[arning], e[rror], and c[ritical].", CommandOptionType.SingleValue); var nocache = app.Option("--no-cache", "Disable caching (Restore and Dll cache)", CommandOptionType.NoValue); + var noNugetCache = app.Option("--no-nuget-cache", "Disable the NuGet restore cache", CommandOptionType.NoValue); var infoOption = app.Option("--info", "Displays environmental information", CommandOptionType.NoValue); var argsBeforeDoubleHyphen = args.TakeWhile(a => a != "--").ToArray(); - var argsAfterDoubleHyphen = args.SkipWhile(a => a != "--").Skip(1).ToArray(); + var argsAfterDoubleHyphen = args.SkipWhile(a => a != "--").Skip(1).ToArray(); const string helpOptionTemplate = "-? | -h | --help"; app.HelpOption(helpOptionTemplate); @@ -98,7 +99,7 @@ private static int Wain(string[] args) } var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue()); - var options = new ExecuteCodeCommandOptions(source, cwd.Value(), app.RemainingArguments.Concat(argsAfterDoubleHyphen).ToArray(),configuration.ValueEquals("release", StringComparison.OrdinalIgnoreCase) ? OptimizationLevel.Release : OptimizationLevel.Debug, nocache.HasValue(),packageSources.Values?.ToArray()); + var options = new ExecuteCodeCommandOptions(source, cwd.Value(), app.RemainingArguments.Concat(argsAfterDoubleHyphen).ToArray(), configuration.ValueEquals("release", StringComparison.OrdinalIgnoreCase) ? OptimizationLevel.Release : OptimizationLevel.Debug, nocache.HasValue(), noNugetCache.HasValue(), packageSources.Values?.ToArray()); return await new ExecuteCodeCommand(ScriptConsole.Default, logFactory).Execute(options); }); }); @@ -137,7 +138,7 @@ private static int Wain(string[] args) }); }); - // windows only + // windows only if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // on windows we have command to register .csx files to be executed by dotnet-script @@ -181,7 +182,8 @@ private static int Wain(string[] args) commandConfig.ValueEquals("release", StringComparison.OrdinalIgnoreCase) ? OptimizationLevel.Release : OptimizationLevel.Debug, packageSources.Values?.ToArray(), runtime.Value() ?? ScriptEnvironment.Default.RuntimeIdentifier, - nocache.HasValue() + nocache.HasValue(), + noNugetCache.HasValue() ); var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue()); @@ -208,7 +210,8 @@ private static int Wain(string[] args) ( dllPath.Value, app.RemainingArguments.Concat(argsAfterDoubleHyphen).ToArray(), - nocache.HasValue() + nocache.HasValue(), + noNugetCache.HasValue() ); var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue()); return await new ExecuteLibraryCommand(ScriptConsole.Default, logFactory).Execute(options); @@ -244,12 +247,13 @@ private static int Wain(string[] args) optimizationLevel, packageSources.Values?.ToArray(), interactive.HasValue(), - nocache.HasValue() + nocache.HasValue(), + noNugetCache.HasValue() ); var fileCommand = new ExecuteScriptCommand(ScriptConsole.Default, logFactory); return await fileCommand.Run(fileCommandOptions); - } + } else { await RunInteractive(!nocache.HasValue(), logFactory, packageSources.Values?.ToArray());