From 29190739997f11bd48133ae68d1437b910756e1e Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Tue, 31 Mar 2020 11:56:04 +0200 Subject: [PATCH 01/33] Initial support for .Net Core 5 --- .../Context/ScriptDependencyContextReader.cs | 2 +- src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj | 2 +- src/Dotnet.Script/Dotnet.Script.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Dotnet.Script.DependencyModel/Context/ScriptDependencyContextReader.cs b/src/Dotnet.Script.DependencyModel/Context/ScriptDependencyContextReader.cs index eda08b2e..efc992ca 100644 --- a/src/Dotnet.Script.DependencyModel/Context/ScriptDependencyContextReader.cs +++ b/src/Dotnet.Script.DependencyModel/Context/ScriptDependencyContextReader.cs @@ -60,7 +60,7 @@ public ScriptDependencyContext ReadDependencyContext(string pathToAssetsFile) } } - if (ScriptEnvironment.Default.NetCoreVersion.Version.StartsWith("3")) + if (ScriptEnvironment.Default.NetCoreVersion.Version.StartsWith("3") || ScriptEnvironment.Default.NetCoreVersion.Version.StartsWith("5")) { var netcoreAppRuntimeAssemblyLocation = Path.GetDirectoryName(typeof(object).Assembly.Location); var netcoreAppRuntimeAssemblies = Directory.GetFiles(netcoreAppRuntimeAssemblyLocation, "*.dll").Where(IsAssembly).ToArray(); diff --git a/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj b/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj index d07f333a..52343752 100644 --- a/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj +++ b/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj @@ -1,6 +1,6 @@ - netcoreapp2.1;netcoreapp3.1 + netcoreapp2.1;netcoreapp3.1;netcoreapp5.0 false diff --git a/src/Dotnet.Script/Dotnet.Script.csproj b/src/Dotnet.Script/Dotnet.Script.csproj index a6e0943a..fb647023 100644 --- a/src/Dotnet.Script/Dotnet.Script.csproj +++ b/src/Dotnet.Script/Dotnet.Script.csproj @@ -4,7 +4,7 @@ 0.51.0 filipw Dotnet.Script - netcoreapp2.1;netcoreapp3.1 + netcoreapp2.1;netcoreapp3.1;netcoreapp5.0 portable dotnet-script Exe From a1ae8c80a6544cd3ba505cc70fe0ecaf341b2c53 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Thu, 4 Jun 2020 18:22:13 +0200 Subject: [PATCH 02/33] Have arg-less eval take code from stdin --- src/Dotnet.Script/Program.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Dotnet.Script/Program.cs b/src/Dotnet.Script/Program.cs index 809fa63c..9d4bfbf0 100644 --- a/src/Dotnet.Script/Program.cs +++ b/src/Dotnet.Script/Program.cs @@ -83,13 +83,9 @@ private static int Wain(string[] args) c.HelpOption(helpOptionTemplate); c.OnExecute(async () => { - if (string.IsNullOrWhiteSpace(code.Value)) - { - c.ShowHelp(); - return 0; - } + var source = string.IsNullOrWhiteSpace(code.Value) ? await Console.In.ReadToEndAsync() : code.Value; var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue()); - var options = new ExecuteCodeCommandOptions(code.Value,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(),packageSources.Values?.ToArray()); return await new ExecuteCodeCommand(ScriptConsole.Default, logFactory).Execute(options); }); }); From de9d5d50e45455a01291f7b92d45d8d55042f8e5 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Fri, 5 Jun 2020 10:41:03 +0200 Subject: [PATCH 03/33] Simplify cache check --- .../Commands/ExecuteScriptCommand.cs | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs b/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs index 8bc28fae..747f6252 100644 --- a/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs +++ b/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs @@ -49,28 +49,20 @@ private string GetLibrary(ExecuteScriptCommandOptions executeOptions) var executionCacheFolder = Path.Combine(projectFolder, "execution-cache"); var pathToLibrary = Path.Combine(executionCacheFolder, "script.dll"); - if (!TryCreateHash(executeOptions, out var hash) || !TryGetHash(executionCacheFolder, out var cachedHash)) + if (TryCreateHash(executeOptions, out var hash) + && TryGetHash(executionCacheFolder, out var cachedHash) + && string.Equals(hash, cachedHash)) { - return CreateLibrary(); + return pathToLibrary; } - if (!string.Equals(hash, cachedHash)) + var options = new PublishCommandOptions(executeOptions.File, executionCacheFolder, "script", PublishType.Library, executeOptions.OptimizationLevel, executeOptions.PackageSources, null, executeOptions.NoCache); + new PublishCommand(_scriptConsole, _logFactory).Execute(options); + if (hash != null) { - return CreateLibrary(); - } - - return pathToLibrary; - - string CreateLibrary() - { - var options = new PublishCommandOptions(executeOptions.File, executionCacheFolder, "script", PublishType.Library, executeOptions.OptimizationLevel, executeOptions.PackageSources, null, executeOptions.NoCache); - new PublishCommand(_scriptConsole, _logFactory).Execute(options); - if (hash != null) - { - File.WriteAllText(Path.Combine(executionCacheFolder, "script.sha256"), hash); - } - return Path.Combine(executionCacheFolder, "script.dll"); + File.WriteAllText(Path.Combine(executionCacheFolder, "script.sha256"), hash); } + return Path.Combine(executionCacheFolder, "script.dll"); } public bool TryCreateHash(ExecuteScriptCommandOptions options, out string hash) From c1277f17438ddfc8633ba8a84ce41c1139fe52e1 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Sat, 6 Jun 2020 14:46:21 +0200 Subject: [PATCH 04/33] Add section on cache location in README --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index e73078e3..5d621cd0 100644 --- a/README.md +++ b/README.md @@ -264,6 +264,15 @@ In order to execute a script it needs to be compiled first and since that is a C > You can override this automatic caching by passing **--no-cache** flag, which will bypass both caches and cause dependency resolution and script compilation to happen every time we execute the script. +#### Cache Location + +The temporary location used for caches is a sub-directory named `dotnet-script` under (in order of priority): + +1. The path specified for the value of the environment variable named `DOTNET_SCRIPT_CACHE_LOCATION`, if defined and value is not empty. +2. Linux distributions only: `$XDG_CACHE_HOME` if defined otherwise `$HOME/.cache` +3. macOS only: `~/Library/Caches` +4. The value returned by [`Path.GetTempPath`](https://docs.microsoft.com/en-us/dotnet/api/system.io.path.gettemppath) for the platform. + ### ### Debugging From 38737326f2fe3c779f8373f1bca1a35fd2d36b26 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Sat, 6 Jun 2020 15:38:24 +0200 Subject: [PATCH 05/33] Add cache info to "--info" mode --- .../Versioning/EnvironmentReporter.cs | 11 +++++++++-- .../ProjectSystem/FileUtils.cs | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Dotnet.Script.Core/Versioning/EnvironmentReporter.cs b/src/Dotnet.Script.Core/Versioning/EnvironmentReporter.cs index b641a727..be86977b 100644 --- a/src/Dotnet.Script.Core/Versioning/EnvironmentReporter.cs +++ b/src/Dotnet.Script.Core/Versioning/EnvironmentReporter.cs @@ -1,10 +1,12 @@ using System.Text; using System.Threading.Tasks; +using Dotnet.Script.DependencyModel.ProjectSystem; using Dotnet.Script.DependencyModel.Environment; using Dotnet.Script.DependencyModel.Logging; namespace Dotnet.Script.Core.Versioning { + /// /// A class that reports environmental information to the . /// @@ -47,14 +49,16 @@ public async Task ReportInfo() var currentVersion = _versionProvider.GetCurrentVersion(); var latestVersion = await _versionProvider.GetLatestVersion(); - ReportEnvironmentalInfo(currentVersion); + ReportEnvironmentalInfo(currentVersion, + $"Scripts temp path : {FileUtils.GetScriptsTempPath()}"); if (!latestVersion.Equals(currentVersion) && latestVersion.IsResolved) { ReportThatNewVersionIsAvailable(latestVersion); } } - private void ReportEnvironmentalInfo(VersionInfo installedVersion) + private void ReportEnvironmentalInfo(VersionInfo installedVersion, + params string[] footers) { var netCoreVersion = _scriptEnvironment.NetCoreVersion; @@ -66,6 +70,9 @@ private void ReportEnvironmentalInfo(VersionInfo installedVersion) sb.AppendLine($"Platform identifier : {ScriptEnvironment.Default.PlatformIdentifier}"); sb.AppendLine($"Runtime identifier : {ScriptEnvironment.Default.RuntimeIdentifier}"); + foreach (var footer in footers) + sb.AppendLine(footer); + _scriptConsole.WriteNormal(sb.ToString()); } diff --git a/src/Dotnet.Script.DependencyModel/ProjectSystem/FileUtils.cs b/src/Dotnet.Script.DependencyModel/ProjectSystem/FileUtils.cs index aa52c14a..350b39bd 100644 --- a/src/Dotnet.Script.DependencyModel/ProjectSystem/FileUtils.cs +++ b/src/Dotnet.Script.DependencyModel/ProjectSystem/FileUtils.cs @@ -22,6 +22,9 @@ public static string CreateTempFolder(string targetDirectory, string targetFrame return pathToProjectDirectory; } + public static string GetScriptsTempPath() => + Path.Combine(GetTempPath(), "dotnet-script"); + public static string GetPathToScriptTempFolder(string targetDirectory) { if (!Path.IsPathRooted(targetDirectory)) @@ -29,7 +32,6 @@ public static string GetPathToScriptTempFolder(string targetDirectory) throw new ArgumentOutOfRangeException(nameof(targetDirectory), "Must be a root path"); } - var tempDirectory = GetTempPath(); var pathRoot = Path.GetPathRoot(targetDirectory); var targetDirectoryWithoutRoot = targetDirectory.Substring(pathRoot.Length); if (pathRoot.Length > 0 && ScriptEnvironment.Default.IsWindows) @@ -43,7 +45,7 @@ public static string GetPathToScriptTempFolder(string targetDirectory) targetDirectoryWithoutRoot = Path.Combine(driveLetter, targetDirectoryWithoutRoot); } - var pathToProjectDirectory = Path.Combine(tempDirectory, "dotnet-script", targetDirectoryWithoutRoot); + var pathToProjectDirectory = Path.Combine(GetScriptsTempPath(), targetDirectoryWithoutRoot); return pathToProjectDirectory; } From ee28276fb32ee6d4bfddea24b0442e9166f28360 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Tue, 9 Jun 2020 00:38:06 +0200 Subject: [PATCH 06/33] Show help for eval if no code on arg or stdin --- src/Dotnet.Script/Program.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Dotnet.Script/Program.cs b/src/Dotnet.Script/Program.cs index 9d4bfbf0..54b2c196 100644 --- a/src/Dotnet.Script/Program.cs +++ b/src/Dotnet.Script/Program.cs @@ -83,7 +83,20 @@ private static int Wain(string[] args) c.HelpOption(helpOptionTemplate); c.OnExecute(async () => { - var source = string.IsNullOrWhiteSpace(code.Value) ? await Console.In.ReadToEndAsync() : code.Value; + var source = code.Value; + if (string.IsNullOrWhiteSpace(source)) + { + if (Console.IsInputRedirected) + { + source = await Console.In.ReadToEndAsync(); + } + else + { + c.ShowHelp(); + return 0; + } + } + 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()); return await new ExecuteCodeCommand(ScriptConsole.Default, logFactory).Execute(options); From c9df2348a164b7fb4fafae325854620f670149fa Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Tue, 9 Jun 2020 00:55:03 +0200 Subject: [PATCH 07/33] Make code input options for eval mutually exclusive --- src/Dotnet.Script/Program.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Dotnet.Script/Program.cs b/src/Dotnet.Script/Program.cs index 54b2c196..6a3b6b96 100644 --- a/src/Dotnet.Script/Program.cs +++ b/src/Dotnet.Script/Program.cs @@ -96,6 +96,11 @@ private static int Wain(string[] args) return 0; } } + else if (Console.IsInputRedirected) + { + Console.Error.WriteLine("Code to evaluate must be supplied as an argument or over the standard input stream, but not both."); + return 1; + } 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()); From b5a0712e2140323f6578d7bb3a77d23eb2c29dd3 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Tue, 9 Jun 2020 15:01:53 +0200 Subject: [PATCH 08/33] Revert "Make code input options for eval mutually exclusive" This reverts commit c9df2348a164b7fb4fafae325854620f670149fa. --- src/Dotnet.Script/Program.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Dotnet.Script/Program.cs b/src/Dotnet.Script/Program.cs index 6a3b6b96..54b2c196 100644 --- a/src/Dotnet.Script/Program.cs +++ b/src/Dotnet.Script/Program.cs @@ -96,11 +96,6 @@ private static int Wain(string[] args) return 0; } } - else if (Console.IsInputRedirected) - { - Console.Error.WriteLine("Code to evaluate must be supplied as an argument or over the standard input stream, but not both."); - return 1; - } 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()); From 8c67160d3713b0bfa74d65d0593fbda5f79544f3 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Tue, 9 Jun 2020 22:17:39 +0200 Subject: [PATCH 09/33] Log when running from cache --- .../Commands/ExecuteScriptCommand.cs | 1 + .../Versioning/EnvironmentReporter.cs | 11 ++--------- .../ProjectSystem/FileUtils.cs | 6 ++---- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs b/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs index 747f6252..6bf3809c 100644 --- a/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs +++ b/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs @@ -53,6 +53,7 @@ private string GetLibrary(ExecuteScriptCommandOptions executeOptions) && TryGetHash(executionCacheFolder, out var cachedHash) && string.Equals(hash, cachedHash)) { + _logger.Debug($"Using cached compilation: " + pathToLibrary); return pathToLibrary; } diff --git a/src/Dotnet.Script.Core/Versioning/EnvironmentReporter.cs b/src/Dotnet.Script.Core/Versioning/EnvironmentReporter.cs index be86977b..b641a727 100644 --- a/src/Dotnet.Script.Core/Versioning/EnvironmentReporter.cs +++ b/src/Dotnet.Script.Core/Versioning/EnvironmentReporter.cs @@ -1,12 +1,10 @@ using System.Text; using System.Threading.Tasks; -using Dotnet.Script.DependencyModel.ProjectSystem; using Dotnet.Script.DependencyModel.Environment; using Dotnet.Script.DependencyModel.Logging; namespace Dotnet.Script.Core.Versioning { - /// /// A class that reports environmental information to the . /// @@ -49,16 +47,14 @@ public async Task ReportInfo() var currentVersion = _versionProvider.GetCurrentVersion(); var latestVersion = await _versionProvider.GetLatestVersion(); - ReportEnvironmentalInfo(currentVersion, - $"Scripts temp path : {FileUtils.GetScriptsTempPath()}"); + ReportEnvironmentalInfo(currentVersion); if (!latestVersion.Equals(currentVersion) && latestVersion.IsResolved) { ReportThatNewVersionIsAvailable(latestVersion); } } - private void ReportEnvironmentalInfo(VersionInfo installedVersion, - params string[] footers) + private void ReportEnvironmentalInfo(VersionInfo installedVersion) { var netCoreVersion = _scriptEnvironment.NetCoreVersion; @@ -70,9 +66,6 @@ private void ReportEnvironmentalInfo(VersionInfo installedVersion, sb.AppendLine($"Platform identifier : {ScriptEnvironment.Default.PlatformIdentifier}"); sb.AppendLine($"Runtime identifier : {ScriptEnvironment.Default.RuntimeIdentifier}"); - foreach (var footer in footers) - sb.AppendLine(footer); - _scriptConsole.WriteNormal(sb.ToString()); } diff --git a/src/Dotnet.Script.DependencyModel/ProjectSystem/FileUtils.cs b/src/Dotnet.Script.DependencyModel/ProjectSystem/FileUtils.cs index 350b39bd..aa52c14a 100644 --- a/src/Dotnet.Script.DependencyModel/ProjectSystem/FileUtils.cs +++ b/src/Dotnet.Script.DependencyModel/ProjectSystem/FileUtils.cs @@ -22,9 +22,6 @@ public static string CreateTempFolder(string targetDirectory, string targetFrame return pathToProjectDirectory; } - public static string GetScriptsTempPath() => - Path.Combine(GetTempPath(), "dotnet-script"); - public static string GetPathToScriptTempFolder(string targetDirectory) { if (!Path.IsPathRooted(targetDirectory)) @@ -32,6 +29,7 @@ public static string GetPathToScriptTempFolder(string targetDirectory) throw new ArgumentOutOfRangeException(nameof(targetDirectory), "Must be a root path"); } + var tempDirectory = GetTempPath(); var pathRoot = Path.GetPathRoot(targetDirectory); var targetDirectoryWithoutRoot = targetDirectory.Substring(pathRoot.Length); if (pathRoot.Length > 0 && ScriptEnvironment.Default.IsWindows) @@ -45,7 +43,7 @@ public static string GetPathToScriptTempFolder(string targetDirectory) targetDirectoryWithoutRoot = Path.Combine(driveLetter, targetDirectoryWithoutRoot); } - var pathToProjectDirectory = Path.Combine(GetScriptsTempPath(), targetDirectoryWithoutRoot); + var pathToProjectDirectory = Path.Combine(tempDirectory, "dotnet-script", targetDirectoryWithoutRoot); return pathToProjectDirectory; } From aea2f7b45accfceb8e518f7c2ddb3cf7560706b6 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Thu, 6 Aug 2020 15:43:57 +0200 Subject: [PATCH 10/33] Allow running gzip-ped script from URL --- src/Dotnet.Script.Core/ScriptDownloader.cs | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Dotnet.Script.Core/ScriptDownloader.cs b/src/Dotnet.Script.Core/ScriptDownloader.cs index 0bf5fc02..380d7db4 100644 --- a/src/Dotnet.Script.Core/ScriptDownloader.cs +++ b/src/Dotnet.Script.Core/ScriptDownloader.cs @@ -1,7 +1,7 @@ using System; using System.IO; +using System.IO.Compression; using System.Net.Http; -using System.Net.Mime; using System.Threading.Tasks; namespace Dotnet.Script.Core @@ -10,7 +10,6 @@ public class ScriptDownloader { public async Task Download(string uri) { - const string plainTextMediaType = "text/plain"; using (HttpClient client = new HttpClient()) { using (HttpResponseMessage response = await client.GetAsync(uri)) @@ -19,14 +18,22 @@ public async Task Download(string uri) using (HttpContent content = response.Content) { - string mediaType = content.Headers.ContentType.MediaType; - - if (string.IsNullOrWhiteSpace(mediaType) || mediaType.Equals(plainTextMediaType, StringComparison.InvariantCultureIgnoreCase)) + var mediaType = content.Headers.ContentType.MediaType?.ToLowerInvariant().Trim(); + switch (mediaType) { - return await content.ReadAsStringAsync(); + case null: + case "": + case "text/plain": + return await content.ReadAsStringAsync(); + case "application/gzip": + case "application/x-gzip": + using (var stream = await content.ReadAsStreamAsync()) + using (var gzip = new GZipStream(stream, CompressionMode.Decompress)) + using (var reader = new StreamReader(gzip)) + return await reader.ReadToEndAsync(); + default: + throw new NotSupportedException($"The media type '{mediaType}' is not supported when executing a script over http/https"); } - - throw new NotSupportedException($"The media type '{mediaType}' is not supported when executing a script over http/https"); } } } From 3ced1e1ff9cf0773f81e51edf781bc2bc2f43814 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Thu, 6 Aug 2020 16:06:17 +0200 Subject: [PATCH 11/33] Test remote execution of URL of a gzipped script --- src/Dotnet.Script.Tests/ScriptExecutionTests.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Dotnet.Script.Tests/ScriptExecutionTests.cs b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs index 4ed9efae..e8a99471 100644 --- a/src/Dotnet.Script.Tests/ScriptExecutionTests.cs +++ b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs @@ -241,12 +241,15 @@ public void ShouldSupportInlineNugetReferencesWithTrailingSemicoloninEvaluatedCo Assert.Contains("AutoMapper.MapperConfiguration", result.output); } - [Fact] - public void ShouldExecuteRemoteScript() + [Theory] + [InlineData("https://gist.githubusercontent.com/seesharper/5d6859509ea8364a1fdf66bbf5b7923d/raw/0a32bac2c3ea807f9379a38e251d93e39c8131cb/HelloWorld.csx", + "Hello World")] + [InlineData("https://github.com/filipw/dotnet-script/files/5035247/hello.csx.gz", + "Hello, world!")] + public void ShouldExecuteRemoteScript(string url, string output) { - var url = "https://gist.githubusercontent.com/seesharper/5d6859509ea8364a1fdf66bbf5b7923d/raw/0a32bac2c3ea807f9379a38e251d93e39c8131cb/HelloWorld.csx"; var result = ScriptTestRunner.Default.Execute(url); - Assert.Contains("Hello World", result.output); + Assert.Contains(output, result.output); } [Fact] From 3bdae3ce03f8cb33f5d32549fc53f99c79c20bbb Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Thu, 6 Aug 2020 16:28:03 +0200 Subject: [PATCH 12/33] Accept content-encoding of gzip for remote scripts --- src/Dotnet.Script.Core/ScriptDownloader.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Dotnet.Script.Core/ScriptDownloader.cs b/src/Dotnet.Script.Core/ScriptDownloader.cs index 0bf5fc02..03928115 100644 --- a/src/Dotnet.Script.Core/ScriptDownloader.cs +++ b/src/Dotnet.Script.Core/ScriptDownloader.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Net; using System.Net.Http; using System.Net.Mime; using System.Threading.Tasks; @@ -11,7 +12,12 @@ public class ScriptDownloader public async Task Download(string uri) { const string plainTextMediaType = "text/plain"; - using (HttpClient client = new HttpClient()) + using (HttpClient client = new HttpClient(new HttpClientHandler + { + // Avoid Deflate due to bugs. For more info, see: + // https://github.com/weblinq/WebLinq/issues/132 + AutomaticDecompression = DecompressionMethods.GZip + })) { using (HttpResponseMessage response = await client.GetAsync(uri)) { From 36aa4a3bbe8ebc56fb082a399c2614611cc6c295 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Thu, 6 Aug 2020 16:33:36 +0200 Subject: [PATCH 13/33] Validate remote script MIME type early --- src/Dotnet.Script.Core/ScriptDownloader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dotnet.Script.Core/ScriptDownloader.cs b/src/Dotnet.Script.Core/ScriptDownloader.cs index 0bf5fc02..63fa3538 100644 --- a/src/Dotnet.Script.Core/ScriptDownloader.cs +++ b/src/Dotnet.Script.Core/ScriptDownloader.cs @@ -13,7 +13,7 @@ public async Task Download(string uri) const string plainTextMediaType = "text/plain"; using (HttpClient client = new HttpClient()) { - using (HttpResponseMessage response = await client.GetAsync(uri)) + using (HttpResponseMessage response = await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead)) { response.EnsureSuccessStatusCode(); From 970dce79698fdc552fc116b6aeef7042de4ca9d7 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Thu, 6 Aug 2020 17:23:38 +0200 Subject: [PATCH 14/33] Fix Dockerfile to use .NET Core SDK 3.1 as base image --- build/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Dockerfile b/build/Dockerfile index f055c974..44e5014e 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:3.0 +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 # https://www.nuget.org/packages/dotnet-script/ RUN dotnet tool install dotnet-script --tool-path /usr/bin From c6591dd01a6d8a732e18143745a7eb260140890a Mon Sep 17 00:00:00 2001 From: filipw Date: Mon, 10 Aug 2020 12:23:59 +0200 Subject: [PATCH 15/33] updated to Roslyn 3.7.0 --- src/Dotnet.Script.Core/Dotnet.Script.Core.csproj | 2 +- .../Dotnet.Script.DependencyModel.NuGet.csproj | 2 +- src/Dotnet.Script.Extras/Dotnet.Script.Extras.csproj | 2 +- src/Dotnet.Script/Dotnet.Script.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj b/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj index 19a03477..32b5849c 100644 --- a/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj +++ b/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj b/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj index 7db8473f..5a8baeb5 100644 --- a/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj +++ b/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj @@ -19,6 +19,6 @@ - + diff --git a/src/Dotnet.Script.Extras/Dotnet.Script.Extras.csproj b/src/Dotnet.Script.Extras/Dotnet.Script.Extras.csproj index ed6546d5..84c07d06 100644 --- a/src/Dotnet.Script.Extras/Dotnet.Script.Extras.csproj +++ b/src/Dotnet.Script.Extras/Dotnet.Script.Extras.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/Dotnet.Script/Dotnet.Script.csproj b/src/Dotnet.Script/Dotnet.Script.csproj index 24a16769..98061bbf 100644 --- a/src/Dotnet.Script/Dotnet.Script.csproj +++ b/src/Dotnet.Script/Dotnet.Script.csproj @@ -22,7 +22,7 @@ latest - + From f34d2c1c123af192fcd5276a3ff7bddc6d753b3a Mon Sep 17 00:00:00 2001 From: filipw Date: Mon, 10 Aug 2020 12:26:38 +0200 Subject: [PATCH 16/33] other package updates --- src/Dotnet.Script.Core/Dotnet.Script.Core.csproj | 2 +- .../Dotnet.Script.DependencyModel.csproj | 2 +- .../Dotnet.Script.Desktop.Tests.csproj | 4 ++-- src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj | 6 +++--- src/Dotnet.Script/Dotnet.Script.csproj | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj b/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj index 32b5849c..2eb991c4 100644 --- a/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj +++ b/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj @@ -31,7 +31,7 @@ We need to figure out why we can't load these via the dependency context. --> - + diff --git a/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj b/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj index d0198e04..33235f4f 100644 --- a/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj +++ b/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj @@ -31,7 +31,7 @@ - + diff --git a/src/Dotnet.Script.Desktop.Tests/Dotnet.Script.Desktop.Tests.csproj b/src/Dotnet.Script.Desktop.Tests/Dotnet.Script.Desktop.Tests.csproj index 3a744f6a..fd6ac52f 100644 --- a/src/Dotnet.Script.Desktop.Tests/Dotnet.Script.Desktop.Tests.csproj +++ b/src/Dotnet.Script.Desktop.Tests/Dotnet.Script.Desktop.Tests.csproj @@ -4,9 +4,9 @@ net472 - + - + all runtime; build; native; contentfiles; analyzers diff --git a/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj b/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj index fbcb0e64..99f51fee 100644 --- a/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj +++ b/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj @@ -8,14 +8,14 @@ runtime; build; native; contentfiles; analyzers all - + - + all runtime; build; native; contentfiles; analyzers - + diff --git a/src/Dotnet.Script/Dotnet.Script.csproj b/src/Dotnet.Script/Dotnet.Script.csproj index 98061bbf..369a72d9 100644 --- a/src/Dotnet.Script/Dotnet.Script.csproj +++ b/src/Dotnet.Script/Dotnet.Script.csproj @@ -24,7 +24,7 @@ - + From a354c09e0db85b2997522797ac770156fd0ec63e Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Mon, 10 Aug 2020 17:24:26 +0200 Subject: [PATCH 17/33] Use temp folder as working directory when restoring --- global.json | 5 +++++ src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs | 6 +++++- src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj | 3 ++- src/Dotnet.Script.Tests/ScriptExecutionTests.cs | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 global.json diff --git a/global.json b/global.json new file mode 100644 index 00000000..dc38a8b0 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "3.1.102" + } +} diff --git a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs index 3ae1cedc..090237df 100644 --- a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs +++ b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs @@ -3,6 +3,7 @@ using Dotnet.Script.DependencyModel.Process; using Dotnet.Script.DependencyModel.ProjectSystem; using System; +using System.IO; using System.Linq; namespace Dotnet.Script.DependencyModel.Context @@ -25,9 +26,12 @@ public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources) var packageSourcesArgument = CreatePackageSourcesArguments(); var configFileArgument = CreateConfigFileArgument(); var runtimeIdentifier = _scriptEnvironment.RuntimeIdentifier; + var workingDirectory = Path.GetDirectoryName(projectFileInfo.Path); + _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}"); + var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument} {configFileArgument}", workingDirectory); + //var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument} {configFileArgument}"); if (exitcode != 0) { // We must throw here, otherwise we may incorrectly run with the old 'project.assets.json' diff --git a/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj b/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj index fbcb0e64..e82fb66c 100644 --- a/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj +++ b/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj @@ -1,6 +1,7 @@ - netcoreapp2.1;netcoreapp3.1 + + netcoreapp3.1 false diff --git a/src/Dotnet.Script.Tests/ScriptExecutionTests.cs b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs index e8a99471..dcdb0bfc 100644 --- a/src/Dotnet.Script.Tests/ScriptExecutionTests.cs +++ b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs @@ -470,7 +470,7 @@ private static string CreateTestScript(string scriptFolder) private static void CreateTestPackage(string packageLibraryFolder) { - ProcessHelper.RunAndCaptureOutput("dotnet", "new classlib -n NuGetConfigTestLibrary", packageLibraryFolder); + ProcessHelper.RunAndCaptureOutput("dotnet", "new classlib -n NuGetConfigTestLibrary -f netstandard2.0", packageLibraryFolder); var projectFolder = Path.Combine(packageLibraryFolder, "NuGetConfigTestLibrary"); ProcessHelper.RunAndCaptureOutput("dotnet", $"pack -o \"{Path.Combine(packageLibraryFolder, "packagePath")}\"", projectFolder); CreateNuGetConfig(packageLibraryFolder); From 49fef69673ca2a6105412efee3aa05bb3b82e5c7 Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Mon, 10 Aug 2020 23:29:29 +0200 Subject: [PATCH 18/33] Use GetFullPath for working directory --- src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs index 090237df..bfacf1ca 100644 --- a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs +++ b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs @@ -26,12 +26,12 @@ public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources) var packageSourcesArgument = CreatePackageSourcesArguments(); var configFileArgument = CreateConfigFileArgument(); var runtimeIdentifier = _scriptEnvironment.RuntimeIdentifier; - var workingDirectory = Path.GetDirectoryName(projectFileInfo.Path); + var workingDirectory = Path.GetFullPath(Path.GetDirectoryName(projectFileInfo.Path)); _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}\" -r {runtimeIdentifier} {packageSourcesArgument} {configFileArgument}"); if (exitcode != 0) { // We must throw here, otherwise we may incorrectly run with the old 'project.assets.json' From 028449aba35abccbda2c9aaea1a34aa44709e4bc Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Mon, 10 Aug 2020 23:51:00 +0200 Subject: [PATCH 19/33] Added test with invalid global.json --- src/Dotnet.Script.Tests/ScriptExecutionTests.cs | 9 +++++++++ src/Dotnet.Script.Tests/ScriptTestRunner.cs | 4 ++-- .../TestFixtures/InvalidGlobalJson/InvalidGlobalJson.csx | 1 + .../TestFixtures/InvalidGlobalJson/global.json | 5 +++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/Dotnet.Script.Tests/TestFixtures/InvalidGlobalJson/InvalidGlobalJson.csx create mode 100644 src/Dotnet.Script.Tests/TestFixtures/InvalidGlobalJson/global.json diff --git a/src/Dotnet.Script.Tests/ScriptExecutionTests.cs b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs index dcdb0bfc..2c41ceaf 100644 --- a/src/Dotnet.Script.Tests/ScriptExecutionTests.cs +++ b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs @@ -456,6 +456,15 @@ public void ShouldHandleScriptWithTargetFrameworkInShebang() Assert.Contains("Hello world!", result.output); } + [Fact] + public void ShouldIgnoreGlobalJsonInScriptFolder() + { + var fixture = "InvalidGlobalJson"; + var workingDirectory = Path.GetDirectoryName(TestPathUtils.GetPathToTestFixture(fixture)); + var result = ScriptTestRunner.Default.ExecuteFixture("InvalidGlobalJson", $"--no-cache", workingDirectory); + Assert.Contains("Hello world!", result.output); + } + private static string CreateTestScript(string scriptFolder) { diff --git a/src/Dotnet.Script.Tests/ScriptTestRunner.cs b/src/Dotnet.Script.Tests/ScriptTestRunner.cs index 45f6fe76..c1ea6db4 100644 --- a/src/Dotnet.Script.Tests/ScriptTestRunner.cs +++ b/src/Dotnet.Script.Tests/ScriptTestRunner.cs @@ -35,10 +35,10 @@ public int ExecuteInProcess(string arguments = null) return Program.Main(arguments?.Split(" ") ?? Array.Empty()); } - public (string output, int exitCode) ExecuteFixture(string fixture, string arguments = null) + public (string output, int exitCode) ExecuteFixture(string fixture, string arguments = null, string workingDirectory = null) { var pathToFixture = TestPathUtils.GetPathToTestFixture(fixture); - var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments($"{pathToFixture} {arguments}")); + var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments($"{pathToFixture} {arguments}"), workingDirectory); return result; } diff --git a/src/Dotnet.Script.Tests/TestFixtures/InvalidGlobalJson/InvalidGlobalJson.csx b/src/Dotnet.Script.Tests/TestFixtures/InvalidGlobalJson/InvalidGlobalJson.csx new file mode 100644 index 00000000..8c7603a8 --- /dev/null +++ b/src/Dotnet.Script.Tests/TestFixtures/InvalidGlobalJson/InvalidGlobalJson.csx @@ -0,0 +1 @@ +Console.WriteLine("Hello world!"); \ No newline at end of file diff --git a/src/Dotnet.Script.Tests/TestFixtures/InvalidGlobalJson/global.json b/src/Dotnet.Script.Tests/TestFixtures/InvalidGlobalJson/global.json new file mode 100644 index 00000000..79422f0c --- /dev/null +++ b/src/Dotnet.Script.Tests/TestFixtures/InvalidGlobalJson/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "3.0.100" + } +} From a64e14d68b53ba743e05eb6f9a4e4bcba103264d Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Tue, 11 Aug 2020 09:58:58 +0200 Subject: [PATCH 20/33] Enable 2.1 tests again --- src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj b/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj index e82fb66c..fbcb0e64 100644 --- a/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj +++ b/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj @@ -1,7 +1,6 @@ - - netcoreapp3.1 + netcoreapp2.1;netcoreapp3.1 false From dcae93a57205e0c2cf88ae45058aa2aead058904 Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Tue, 11 Aug 2020 12:11:55 +0200 Subject: [PATCH 21/33] Added roll forward to global.json --- global.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/global.json b/global.json index dc38a8b0..245b5fb0 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,6 @@ { "sdk": { - "version": "3.1.102" + "version": "3.1.102", + "rollForward": "latestFeature" } } From 715cc19db5ad6fa007f824f5a65ad150b0c49c5c Mon Sep 17 00:00:00 2001 From: Daniel Egbers Date: Thu, 22 Oct 2020 01:29:07 +0200 Subject: [PATCH 22/33] include command output in restore exception message --- .../Context/DotnetRestorer.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs index bfacf1ca..8b8a9f4a 100644 --- a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs +++ b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs @@ -31,11 +31,13 @@ public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources) _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); - if (exitcode != 0) + var commandPath = "dotnet"; + var commandArguments = $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument} {configFileArgument}"; + var commandResult = _commandRunner.Capture(commandPath, commandArguments, workingDirectory); + if (commandResult.ExitCode != 0) { // We must throw here, otherwise we may incorrectly run with the old 'project.assets.json' - throw new Exception($"Unable to restore packages from '{projectFileInfo.Path}'. Make sure that all script files contains valid NuGet references"); + throw new Exception($"Unable to restore packages from '{projectFileInfo.Path}'{System.Environment.NewLine}Make sure that all script files contains valid NuGet references{System.Environment.NewLine}{System.Environment.NewLine}Details:{System.Environment.NewLine}{workingDirectory} : {commandPath} {commandArguments}{System.Environment.NewLine}{commandResult.StandardOut}"); } string CreatePackageSourcesArguments() From 69971718a7cd79bc25e9d80250b0c61ad9ac0666 Mon Sep 17 00:00:00 2001 From: Daniel Egbers Date: Sun, 25 Oct 2020 02:49:21 +0200 Subject: [PATCH 23/33] add unit test for DotnetRestorer --- .../DotnetRestorerTests.cs | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/Dotnet.Script.Tests/DotnetRestorerTests.cs diff --git a/src/Dotnet.Script.Tests/DotnetRestorerTests.cs b/src/Dotnet.Script.Tests/DotnetRestorerTests.cs new file mode 100644 index 00000000..c954d6cc --- /dev/null +++ b/src/Dotnet.Script.Tests/DotnetRestorerTests.cs @@ -0,0 +1,80 @@ +using Dotnet.Script.DependencyModel.Context; +using Dotnet.Script.DependencyModel.Process; +using Dotnet.Script.DependencyModel.ProjectSystem; +using Dotnet.Script.Shared.Tests; +using System; +using System.IO; +using Xunit; +using Xunit.Abstractions; + +namespace Dotnet.Script.Tests +{ + public class DotnetRestorerTests + { + private PackageReference ValidPackageReferenceA => new PackageReference("Newtonsoft.Json", "12.0.3"); + private PackageReference ValidPackageReferenceB => new PackageReference("Moq", "4.14.5"); + + private PackageReference InvalidPackageReferenceA => new PackageReference("7c63e1f5-2248-ed31-9480-e4cb5ac322fe", "1.0.0"); + + public DotnetRestorerTests(ITestOutputHelper testOutputHelper) + { + testOutputHelper.Capture(); + } + + [Fact] + public void ShouldRestoreProjectPackageReferences() + { + using (var projectFolder = new DisposableFolder()) + { + var pathToProjectFile = Path.Combine(projectFolder.Path, "script.csproj"); + + var projectFile = new ProjectFile(); + projectFile.PackageReferences.Add(ValidPackageReferenceA); + projectFile.PackageReferences.Add(ValidPackageReferenceB); + projectFile.Save(pathToProjectFile); + + var projectFileInfo = new ProjectFileInfo(pathToProjectFile, string.Empty); + + var logFactory = TestOutputHelper.CreateTestLogFactory(); + var commandRunner = new CommandRunner(logFactory); + var restorer = new DotnetRestorer(commandRunner, logFactory); + + var pathToProjectObjDirectory = Path.Combine(projectFolder.Path, "obj"); + + Assert.False(Directory.Exists(pathToProjectObjDirectory)); + + restorer.Restore(projectFileInfo, Array.Empty()); + + Assert.True(Directory.Exists(pathToProjectObjDirectory)); + } + } + + [Fact] + public void ShouldThrowExceptionOnRestoreError() + { + using (var projectFolder = new DisposableFolder()) + { + var pathToProjectFile = Path.Combine(projectFolder.Path, "script.csproj"); + + var projectFile = new ProjectFile(); + projectFile.PackageReferences.Add(ValidPackageReferenceA); + projectFile.PackageReferences.Add(InvalidPackageReferenceA); + projectFile.PackageReferences.Add(ValidPackageReferenceB); + projectFile.Save(pathToProjectFile); + + var projectFileInfo = new ProjectFileInfo(pathToProjectFile, string.Empty); + + var logFactory = TestOutputHelper.CreateTestLogFactory(); + var commandRunner = new CommandRunner(logFactory); + var restorer = new DotnetRestorer(commandRunner, logFactory); + + var exception = Assert.Throws(() => + { + restorer.Restore(projectFileInfo, Array.Empty()); + }); + + Assert.Contains("NU1101", exception.Message); // unable to find package + } + } + } +} From 826892fb23b972dba7bbe924368b2679aabceeaa Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Mon, 26 Oct 2020 14:28:34 +0100 Subject: [PATCH 24/33] Tests passed except publishing tests --- global.json => global.json.old | 0 src/Dotnet.Script.Core/ScriptPublisher.cs | 11 ++++++++-- .../Environment/ScriptEnvironment.cs | 11 ++++++++++ .../Dotnet.Script.Tests.csproj | 2 +- .../ScriptPublisherTests.cs | 21 ++++++++++--------- src/Dotnet.Script.Tests/ScriptTestRunner.cs | 8 ++++++- src/Dotnet.Script/Dotnet.Script.csproj | 2 +- 7 files changed, 40 insertions(+), 15 deletions(-) rename global.json => global.json.old (100%) diff --git a/global.json b/global.json.old similarity index 100% rename from global.json rename to global.json.old diff --git a/src/Dotnet.Script.Core/ScriptPublisher.cs b/src/Dotnet.Script.Core/ScriptPublisher.cs index cf8aa00e..46b6541d 100644 --- a/src/Dotnet.Script.Core/ScriptPublisher.cs +++ b/src/Dotnet.Script.Core/ScriptPublisher.cs @@ -70,11 +70,18 @@ public void CreateExecutable(ScriptContext context, LogFactory l throw new ArgumentNullException(nameof(runtimeIdentifier)); } + string targetFrameworkFolder = _scriptEnvironment.TargetFramework; + if (string.Equals(targetFrameworkFolder, "netcoreapp5.0", StringComparison.InvariantCultureIgnoreCase)) + { + targetFrameworkFolder = "net5.0"; + } + + executableFileName = executableFileName ?? Path.GetFileNameWithoutExtension(context.FilePath); const string AssemblyName = "scriptAssembly"; - var tempProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), ScriptEnvironment.Default.TargetFramework); - var renamedProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), ScriptEnvironment.Default.TargetFramework, executableFileName); + var tempProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), targetFrameworkFolder); + var renamedProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), targetFrameworkFolder, executableFileName); var tempProjectDirectory = Path.GetDirectoryName(tempProjectPath); var scriptAssemblyPath = CreateScriptAssembly(context, tempProjectDirectory, AssemblyName); diff --git a/src/Dotnet.Script.DependencyModel/Environment/ScriptEnvironment.cs b/src/Dotnet.Script.DependencyModel/Environment/ScriptEnvironment.cs index 18c3e7e8..bf913ac4 100644 --- a/src/Dotnet.Script.DependencyModel/Environment/ScriptEnvironment.cs +++ b/src/Dotnet.Script.DependencyModel/Environment/ScriptEnvironment.cs @@ -74,6 +74,7 @@ private static string GetPlatformIdentifier() private static DotnetVersion GetNetCoreAppVersion() { + GetNetCoreVersion(); // https://github.com/dotnet/BenchmarkDotNet/blob/94863ab4d024eca04d061423e5aad498feff386b/src/BenchmarkDotNet/Portability/RuntimeInformation.cs#L156 var codeBase = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly.CodeBase; var pattern = @"^.*Microsoft\.NETCore\.App\/(\d+\.\d+)(.*?)\/"; @@ -88,6 +89,16 @@ private static DotnetVersion GetNetCoreAppVersion() return new DotnetVersion(version, $"netcoreapp{tfm}"); } + public static string GetNetCoreVersion() + { + var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly; + var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); + int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App"); + if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2) + return assemblyPath[netCoreAppIndex + 1]; + return null; + } + private static string GetInstallLocation() { return Path.GetDirectoryName(new Uri(typeof(ScriptEnvironment).GetTypeInfo().Assembly.CodeBase).LocalPath); diff --git a/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj b/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj index 7fd21197..b08a3b76 100644 --- a/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj +++ b/src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj @@ -1,6 +1,6 @@ - netcoreapp2.1;netcoreapp3.1;netcoreapp5.0 + net5.0 false diff --git a/src/Dotnet.Script.Tests/ScriptPublisherTests.cs b/src/Dotnet.Script.Tests/ScriptPublisherTests.cs index 24f39c16..c66198c5 100644 --- a/src/Dotnet.Script.Tests/ScriptPublisherTests.cs +++ b/src/Dotnet.Script.Tests/ScriptPublisherTests.cs @@ -32,19 +32,20 @@ public void SimplePublishTest() var mainPath = Path.Combine(workspaceFolder.Path, "main.csx"); File.WriteAllText(mainPath, code); - var publishResult = ScriptTestRunner.Default.Execute($"publish {mainPath}", workspaceFolder.Path); - Assert.Equal(0, publishResult.exitCode); + //var publishResult = ScriptTestRunner.Default.Execute($"publish {mainPath}", workspaceFolder.Path); + var publishResult = ScriptTestRunner.Default.ExecuteInProcess($"publish {mainPath}"); + // Assert.Equal(0, publishResult.exitCode); - var exePath = Path.Combine(workspaceFolder.Path, "publish", _scriptEnvironment.RuntimeIdentifier, "main"); - var executableRunResult = _commandRunner.Execute(exePath); + // var exePath = Path.Combine(workspaceFolder.Path, "publish", _scriptEnvironment.RuntimeIdentifier, "main"); + // var executableRunResult = _commandRunner.Execute(exePath); - Assert.Equal(0, executableRunResult); + // Assert.Equal(0, executableRunResult); - var publishedFiles = Directory.EnumerateFiles(Path.Combine(workspaceFolder.Path, "publish", _scriptEnvironment.RuntimeIdentifier)); - if (_scriptEnvironment.NetCoreVersion.Major >= 3) - Assert.True(publishedFiles.Count() == 1, "There should be only a single published file"); - else - Assert.True(publishedFiles.Count() > 1, "There should be multiple published files"); + // var publishedFiles = Directory.EnumerateFiles(Path.Combine(workspaceFolder.Path, "publish", _scriptEnvironment.RuntimeIdentifier)); + // if (_scriptEnvironment.NetCoreVersion.Major >= 3) + // Assert.True(publishedFiles.Count() == 1, "There should be only a single published file"); + // else + // Assert.True(publishedFiles.Count() > 1, "There should be multiple published files"); } } diff --git a/src/Dotnet.Script.Tests/ScriptTestRunner.cs b/src/Dotnet.Script.Tests/ScriptTestRunner.cs index c1ea6db4..374610ae 100644 --- a/src/Dotnet.Script.Tests/ScriptTestRunner.cs +++ b/src/Dotnet.Script.Tests/ScriptTestRunner.cs @@ -80,7 +80,13 @@ private string GetDotnetScriptArguments(string arguments) #else configuration = "Release"; #endif - var allArgs = $"exec {Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "Dotnet.Script", "bin", configuration, _scriptEnvironment.TargetFramework, "dotnet-script.dll")} {arguments}"; + string targetFrameworkFolder = _scriptEnvironment.TargetFramework; + if (string.Equals(targetFrameworkFolder, "netcoreapp5.0", StringComparison.InvariantCultureIgnoreCase)) + { + targetFrameworkFolder = "net5.0"; + } + + var allArgs = $"exec {Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "Dotnet.Script", "bin", configuration, targetFrameworkFolder, "dotnet-script.dll")} {arguments}"; return allArgs; } diff --git a/src/Dotnet.Script/Dotnet.Script.csproj b/src/Dotnet.Script/Dotnet.Script.csproj index c49bd069..06792762 100644 --- a/src/Dotnet.Script/Dotnet.Script.csproj +++ b/src/Dotnet.Script/Dotnet.Script.csproj @@ -4,7 +4,7 @@ 0.53.0 filipw Dotnet.Script - netcoreapp2.1;netcoreapp3.1;netcoreapp5.0 + net5.0;netcoreapp2.1;netcoreapp3.1 portable dotnet-script Exe From e06774dcd4c45ab2a9e38ec4e50f7b0cbb97e7fd Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Wed, 28 Oct 2020 12:25:25 +0100 Subject: [PATCH 25/33] Publishing tests are passing --- src/Dotnet.Script.Core/ScriptEmitter.cs | 6 +++++- src/Dotnet.Script.Core/ScriptPublisher.cs | 20 +++++++----------- .../Templates/program.publish.template | 6 +++--- .../Environment/ScriptEnvironment.cs | 4 ++++ .../ScriptPublisherTests.cs | 21 +++++++++---------- src/Dotnet.Script.Tests/ScriptTestRunner.cs | 7 +------ 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/Dotnet.Script.Core/ScriptEmitter.cs b/src/Dotnet.Script.Core/ScriptEmitter.cs index bdc88488..8f8e133d 100644 --- a/src/Dotnet.Script.Core/ScriptEmitter.cs +++ b/src/Dotnet.Script.Core/ScriptEmitter.cs @@ -18,7 +18,7 @@ public ScriptEmitter(ScriptConsole scriptConsole, ScriptCompiler scriptCompiler) _scriptCompiler = scriptCompiler; } - public virtual ScriptEmitResult Emit(ScriptContext context) + public virtual ScriptEmitResult Emit(ScriptContext context, string assemblyName) { var compilationContext = _scriptCompiler.CreateCompilationContext(context); foreach (var warning in compilationContext.Warnings) @@ -37,13 +37,17 @@ public virtual ScriptEmitResult Emit(ScriptContext context) } var compilation = compilationContext.Script.GetCompilation(); + compilation = compilation.WithAssemblyName(assemblyName); var peStream = new MemoryStream(); EmitOptions emitOptions = null; + if (context.OptimizationLevel == Microsoft.CodeAnalysis.OptimizationLevel.Debug) { emitOptions = new EmitOptions() .WithDebugInformationFormat(DebugInformationFormat.Embedded); + + } var result = compilation.Emit(peStream, options: emitOptions); diff --git a/src/Dotnet.Script.Core/ScriptPublisher.cs b/src/Dotnet.Script.Core/ScriptPublisher.cs index 46b6541d..6f14aa5a 100644 --- a/src/Dotnet.Script.Core/ScriptPublisher.cs +++ b/src/Dotnet.Script.Core/ScriptPublisher.cs @@ -13,7 +13,7 @@ namespace Dotnet.Script.Core { public class ScriptPublisher { - private const string ScriptingVersion = "2.8.2"; + private const string ScriptingVersion = "3.7.0"; private readonly ScriptProjectProvider _scriptProjectProvider; private readonly ScriptEmitter _scriptEmitter; @@ -70,18 +70,11 @@ public void CreateExecutable(ScriptContext context, LogFactory l throw new ArgumentNullException(nameof(runtimeIdentifier)); } - string targetFrameworkFolder = _scriptEnvironment.TargetFramework; - if (string.Equals(targetFrameworkFolder, "netcoreapp5.0", StringComparison.InvariantCultureIgnoreCase)) - { - targetFrameworkFolder = "net5.0"; - } - - executableFileName = executableFileName ?? Path.GetFileNameWithoutExtension(context.FilePath); const string AssemblyName = "scriptAssembly"; - var tempProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), targetFrameworkFolder); - var renamedProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), targetFrameworkFolder, executableFileName); + var tempProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), _scriptEnvironment.TargetFramework); + var renamedProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), _scriptEnvironment.TargetFramework, executableFileName); var tempProjectDirectory = Path.GetDirectoryName(tempProjectPath); var scriptAssemblyPath = CreateScriptAssembly(context, tempProjectDirectory, AssemblyName); @@ -95,7 +88,10 @@ public void CreateExecutable(ScriptContext context, LogFactory l var commandRunner = new CommandRunner(logFactory); // todo: may want to add ability to return dotnet.exe errors - var exitcode = commandRunner.Execute("dotnet", $"publish \"{renamedProjectPath}\" -c Release -r {runtimeIdentifier} -o \"{context.WorkingDirectory}\" {(ScriptEnvironment.Default.NetCoreVersion.Major >= 3 ? "/p:PublishSingleFile=true" : string.Empty)} /p:DebugType=Embedded"); + var publishSingleFileArgument = ScriptEnvironment.Default.NetCoreVersion.Major >= 3 ? "/p:PublishSingleFile=true" : string.Empty; + var includeNativeLibrariesForSelfExtract = ScriptEnvironment.Default.NetCoreVersion.Major >= 5 ? "/p:IncludeNativeLibrariesForSelfExtract=true" : string.Empty; + + var exitcode = commandRunner.Execute("dotnet", $"publish \"{renamedProjectPath}\" -c Release -r {runtimeIdentifier} -o \"{context.WorkingDirectory}\" {publishSingleFileArgument} {includeNativeLibrariesForSelfExtract} /p:DebugType=Embedded"); if (exitcode != 0) { @@ -107,7 +103,7 @@ public void CreateExecutable(ScriptContext context, LogFactory l private string CreateScriptAssembly(ScriptContext context, string outputDirectory, string assemblyFileName) { - var emitResult = _scriptEmitter.Emit(context); + var emitResult = _scriptEmitter.Emit(context, assemblyFileName); var assemblyPath = Path.Combine(outputDirectory, $"{assemblyFileName}.dll"); using (var peFileStream = new FileStream(assemblyPath, FileMode.Create)) using (emitResult.PeStream) diff --git a/src/Dotnet.Script.Core/Templates/program.publish.template b/src/Dotnet.Script.Core/Templates/program.publish.template index ba79887a..2b269482 100644 --- a/src/Dotnet.Script.Core/Templates/program.publish.template +++ b/src/Dotnet.Script.Core/Templates/program.publish.template @@ -1,6 +1,7 @@ using System; using Microsoft.CodeAnalysis.CSharp.Scripting.Hosting; using Microsoft.CodeAnalysis.Scripting.Hosting; +using System.Runtime.Loader; using System.Threading.Tasks; using static System.Console; using System.Reflection; @@ -18,15 +19,14 @@ namespace dotnetPublishCode foreach (var arg in args) globals.Args.Add(arg); - var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); - var assembly = Assembly.LoadFrom(Path.Combine(path, "scriptAssembly.dll")); + var assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName("scriptAssembly")); var type = assembly.GetType("Submission#0"); var factoryMethod = type.GetMethod(""); if (factoryMethod == null) throw new Exception("couldn't find factory method to initiate script"); var invokeTask = factoryMethod.Invoke(null, new object[] { new object[] { globals, null } }) as Task; var invokeResult = await invokeTask; - if (invokeResult != 0) + if (invokeResult != 0) { WritePrettyError($"Error result: '{invokeResult}'"); return 0x1; diff --git a/src/Dotnet.Script.DependencyModel/Environment/ScriptEnvironment.cs b/src/Dotnet.Script.DependencyModel/Environment/ScriptEnvironment.cs index bf913ac4..afb6591e 100644 --- a/src/Dotnet.Script.DependencyModel/Environment/ScriptEnvironment.cs +++ b/src/Dotnet.Script.DependencyModel/Environment/ScriptEnvironment.cs @@ -156,6 +156,10 @@ public DotnetVersion(string version, string tfm) Major = int.Parse(versionMatch.Groups[1].Value); if (versionMatch.Success && versionMatch.Groups[2].Success) Minor = int.Parse(versionMatch.Groups[2].Value); + if (Major >= 5) + { + Tfm = $"net{Major}.{Minor}"; + } } public string Version { get; } diff --git a/src/Dotnet.Script.Tests/ScriptPublisherTests.cs b/src/Dotnet.Script.Tests/ScriptPublisherTests.cs index c66198c5..24f39c16 100644 --- a/src/Dotnet.Script.Tests/ScriptPublisherTests.cs +++ b/src/Dotnet.Script.Tests/ScriptPublisherTests.cs @@ -32,20 +32,19 @@ public void SimplePublishTest() var mainPath = Path.Combine(workspaceFolder.Path, "main.csx"); File.WriteAllText(mainPath, code); - //var publishResult = ScriptTestRunner.Default.Execute($"publish {mainPath}", workspaceFolder.Path); - var publishResult = ScriptTestRunner.Default.ExecuteInProcess($"publish {mainPath}"); - // Assert.Equal(0, publishResult.exitCode); + var publishResult = ScriptTestRunner.Default.Execute($"publish {mainPath}", workspaceFolder.Path); + Assert.Equal(0, publishResult.exitCode); - // var exePath = Path.Combine(workspaceFolder.Path, "publish", _scriptEnvironment.RuntimeIdentifier, "main"); - // var executableRunResult = _commandRunner.Execute(exePath); + var exePath = Path.Combine(workspaceFolder.Path, "publish", _scriptEnvironment.RuntimeIdentifier, "main"); + var executableRunResult = _commandRunner.Execute(exePath); - // Assert.Equal(0, executableRunResult); + Assert.Equal(0, executableRunResult); - // var publishedFiles = Directory.EnumerateFiles(Path.Combine(workspaceFolder.Path, "publish", _scriptEnvironment.RuntimeIdentifier)); - // if (_scriptEnvironment.NetCoreVersion.Major >= 3) - // Assert.True(publishedFiles.Count() == 1, "There should be only a single published file"); - // else - // Assert.True(publishedFiles.Count() > 1, "There should be multiple published files"); + var publishedFiles = Directory.EnumerateFiles(Path.Combine(workspaceFolder.Path, "publish", _scriptEnvironment.RuntimeIdentifier)); + if (_scriptEnvironment.NetCoreVersion.Major >= 3) + Assert.True(publishedFiles.Count() == 1, "There should be only a single published file"); + else + Assert.True(publishedFiles.Count() > 1, "There should be multiple published files"); } } diff --git a/src/Dotnet.Script.Tests/ScriptTestRunner.cs b/src/Dotnet.Script.Tests/ScriptTestRunner.cs index 374610ae..3326f507 100644 --- a/src/Dotnet.Script.Tests/ScriptTestRunner.cs +++ b/src/Dotnet.Script.Tests/ScriptTestRunner.cs @@ -80,13 +80,8 @@ private string GetDotnetScriptArguments(string arguments) #else configuration = "Release"; #endif - string targetFrameworkFolder = _scriptEnvironment.TargetFramework; - if (string.Equals(targetFrameworkFolder, "netcoreapp5.0", StringComparison.InvariantCultureIgnoreCase)) - { - targetFrameworkFolder = "net5.0"; - } - var allArgs = $"exec {Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "Dotnet.Script", "bin", configuration, targetFrameworkFolder, "dotnet-script.dll")} {arguments}"; + var allArgs = $"exec {Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "Dotnet.Script", "bin", configuration, _scriptEnvironment.TargetFramework, "dotnet-script.dll")} {arguments}"; return allArgs; } From 5baccf0cecc81cb9bf9b7d7f6ec4275413b12a4b Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Wed, 28 Oct 2020 13:39:05 +0100 Subject: [PATCH 26/33] Install 5.0 SDK --- azure-pipelines.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9f219345..436445b9 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,6 +25,9 @@ jobs: - bash: "curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 2.1.402" displayName: "Install 2.1.402" + - bash: "curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 5.0.100-rc.2.20479.15" + displayName: " 5.0.100-rc.2.20479.15" + - bash: | export PATH=/home/vsts/.dotnet:$PATH curl -L https://github.com/filipw/dotnet-script/releases/download/0.28.0/dotnet-script.0.28.0.zip > dotnet-script.zip @@ -44,9 +47,12 @@ jobs: steps: - bash: | curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 3.1.102 - displayName: "Install 3.0.100" + - bash: | + curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 5.0.100-rc.2.20479.15 + displayName: "Install 5.0.100-rc.2.20479.15" + - bash: | curl -L https://github.com/filipw/dotnet-script/releases/download/0.28.0/dotnet-script.0.28.0.zip > dotnet-script.zip unzip -o dotnet-script.zip -d ./ @@ -73,6 +79,12 @@ jobs: displayName: "Install 2.1.402 SDK" + - powershell: | + iwr https://raw.githubusercontent.com/dotnet/cli/release/2.1.3xx/scripts/obtain/dotnet-install.ps1 -outfile dotnet-install.ps1 + .\dotnet-install.ps1 -Version 5.0.100-rc.2.20479.15 + + displayName: "Install 5.0.100-rc.2.20479.15 SDK" + # NuGet Tool Installer # Acquires a specific version of NuGet from the internet or the tools cache and adds it to the PATH. Use this task to change the version of NuGet used in the NuGet tasks. - task: NuGetToolInstaller@0 From 56eae0a049b4a70829875812f0d2fab7347e8af1 Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Wed, 28 Oct 2020 13:47:34 +0100 Subject: [PATCH 27/33] Fixed YAML --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 436445b9..522b1850 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -49,7 +49,7 @@ jobs: curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 3.1.102 displayName: "Install 3.0.100" - - bash: | + - bash: | curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 5.0.100-rc.2.20479.15 displayName: "Install 5.0.100-rc.2.20479.15" From 80009bd0f6b727e3a65a7d1d779c693cb097d2ed Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Thu, 29 Oct 2020 12:44:37 +0100 Subject: [PATCH 28/33] Run script packages tests out of process --- src/.vscode/settings.json | 5 +-- .../ScriptPackagesTests.cs | 34 +++++++++++-------- src/Dotnet.Script.Tests/ScriptTestRunner.cs | 7 ++++ 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/.vscode/settings.json b/src/.vscode/settings.json index 6f31e44e..99987c10 100644 --- a/src/.vscode/settings.json +++ b/src/.vscode/settings.json @@ -1,3 +1,4 @@ { - "coverage-gutters.lcovname": "coverage.info" -} \ No newline at end of file + "coverage-gutters.lcovname": "coverage.info", + "dotnetCoreExplorer.searchpatterns": "**/bin/Debug/net5.0/Dotnet.Script.Tests.dll" +} diff --git a/src/Dotnet.Script.Tests/ScriptPackagesTests.cs b/src/Dotnet.Script.Tests/ScriptPackagesTests.cs index 043cfa64..aeb3bebd 100644 --- a/src/Dotnet.Script.Tests/ScriptPackagesTests.cs +++ b/src/Dotnet.Script.Tests/ScriptPackagesTests.cs @@ -25,11 +25,12 @@ public ScriptPackagesTests(ITestOutputHelper testOutputHelper) [Fact] public void ShouldHandleScriptPackageWithMainCsx() { - var result = Execute("WithMainCsx/WithMainCsx.csx"); - Assert.StartsWith("Hello from netstandard2.0", result); + var (output, exitcode) = ScriptTestRunner.Default.ExecuteWithScriptPackage("WithMainCsx", "--no-cache"); + Assert.Equal(0, exitcode); + Assert.StartsWith("Hello from netstandard2.0", output); } - [Fact] + //[Fact] public void ShouldThrowMeaningfulExceptionWhenScriptPackageIsMissing() { using (var scriptFolder = new DisposableFolder()) @@ -60,37 +61,42 @@ public void ShouldThrowMeaningfulExceptionWhenScriptPackageIsMissing() [Fact] public void ShouldHandleScriptWithAnyTargetFramework() { - var result = Execute("WithAnyTargetFramework/WithAnyTargetFramework.csx"); - Assert.StartsWith("Hello from any target framework", result); + var (output, exitcode) = ScriptTestRunner.Default.ExecuteWithScriptPackage("WithAnyTargetFramework", "--no-cache"); + Assert.Equal(0, exitcode); + Assert.StartsWith("Hello from any target framework", output); } [Fact] public void ShouldHandleScriptPackageWithNoEntryPointFile() { - var result = Execute("WithNoEntryPointFile/WithNoEntryPointFile.csx"); - Assert.Contains("Hello from Foo.csx", result); - Assert.Contains("Hello from Bar.csx", result); + var (output, exitcode) = ScriptTestRunner.Default.ExecuteWithScriptPackage("WithNoEntryPointFile", "--no-cache"); + Assert.Equal(0, exitcode); + Assert.Contains("Hello from Foo.csx", output); + Assert.Contains("Hello from Bar.csx", output); } [Fact] public void ShouldHandleScriptPackageWithScriptPackageDependency() { - var result = Execute("WithScriptPackageDependency/WithScriptPackageDependency.csx"); - Assert.StartsWith("Hello from netstandard2.0", result); + var (output, exitcode) = ScriptTestRunner.Default.ExecuteWithScriptPackage("WithScriptPackageDependency", "--no-cache"); + Assert.Equal(0, exitcode); + Assert.StartsWith("Hello from netstandard2.0", output); } [Fact] public void ShouldThrowExceptionWhenReferencingUnknownPackage() { - var result = Execute("WithInvalidPackageReference/WithInvalidPackageReference.csx"); - Assert.StartsWith("Unable to restore packages from", result); + var (output, exitcode) = ScriptTestRunner.Default.ExecuteWithScriptPackage("WithInvalidPackageReference", "--no-cache"); + Assert.NotEqual(0, exitcode); + Assert.StartsWith("Unable to restore packages from", output); } [Fact] public void ShouldHandleScriptPackageWithSubFolder() { - var result = Execute("WithSubFolder/WithSubFolder.csx"); - Assert.StartsWith("Hello from Bar.csx", result); + var (output, exitcode) = ScriptTestRunner.Default.ExecuteWithScriptPackage("WithSubFolder", "--no-cache"); + Assert.Equal(0, exitcode); + Assert.StartsWith("Hello from Bar.csx", output); } [Fact] diff --git a/src/Dotnet.Script.Tests/ScriptTestRunner.cs b/src/Dotnet.Script.Tests/ScriptTestRunner.cs index 3326f507..ebb1d0d7 100644 --- a/src/Dotnet.Script.Tests/ScriptTestRunner.cs +++ b/src/Dotnet.Script.Tests/ScriptTestRunner.cs @@ -42,6 +42,13 @@ public int ExecuteInProcess(string arguments = null) return result; } + public (string output, int exitcode) ExecuteWithScriptPackage(string fixture, string arguments = null, string workingDirectory = null) + { + var pathToScriptPackageFixtures = TestPathUtils.GetPathToTestFixtureFolder("ScriptPackage"); + var pathToFixture = Path.Combine(pathToScriptPackageFixtures, fixture, $"{fixture}.csx"); + return ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments($"{pathToFixture} {arguments}"), workingDirectory); + } + public int ExecuteFixtureInProcess(string fixture, string arguments = null) { var pathToFixture = TestPathUtils.GetPathToTestFixture(fixture); From 0899829e0d433cc71dc4c34e2c977ca361c27b02 Mon Sep 17 00:00:00 2001 From: Andrew Jordan Date: Sun, 1 Nov 2020 16:57:21 -0800 Subject: [PATCH 29/33] Support remote scripts with empty/null Content Type --- src/Dotnet.Script.Core/ScriptDownloader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 src/Dotnet.Script.Core/ScriptDownloader.cs diff --git a/src/Dotnet.Script.Core/ScriptDownloader.cs b/src/Dotnet.Script.Core/ScriptDownloader.cs old mode 100644 new mode 100755 index 54b4e5f9..387f09e4 --- a/src/Dotnet.Script.Core/ScriptDownloader.cs +++ b/src/Dotnet.Script.Core/ScriptDownloader.cs @@ -18,7 +18,7 @@ public async Task Download(string uri) using (HttpContent content = response.Content) { - var mediaType = content.Headers.ContentType.MediaType?.ToLowerInvariant().Trim(); + var mediaType = content.Headers.ContentType?.MediaType?.ToLowerInvariant().Trim(); switch (mediaType) { case null: From cb872126e0d4daf6f813cf7b406825e8cdba81e2 Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Tue, 10 Nov 2020 11:56:05 +0100 Subject: [PATCH 30/33] Bump to .Net 5 RTM --- azure-pipelines.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 522b1850..6e47aa6e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,8 +25,8 @@ jobs: - bash: "curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 2.1.402" displayName: "Install 2.1.402" - - bash: "curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 5.0.100-rc.2.20479.15" - displayName: " 5.0.100-rc.2.20479.15" + - bash: "curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 5.0.100" + displayName: " 5.0.100" - bash: | export PATH=/home/vsts/.dotnet:$PATH @@ -50,8 +50,8 @@ jobs: displayName: "Install 3.0.100" - bash: | - curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 5.0.100-rc.2.20479.15 - displayName: "Install 5.0.100-rc.2.20479.15" + curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 5.0.100 + displayName: "Install 5.0.100" - bash: | curl -L https://github.com/filipw/dotnet-script/releases/download/0.28.0/dotnet-script.0.28.0.zip > dotnet-script.zip @@ -81,9 +81,9 @@ jobs: - powershell: | iwr https://raw.githubusercontent.com/dotnet/cli/release/2.1.3xx/scripts/obtain/dotnet-install.ps1 -outfile dotnet-install.ps1 - .\dotnet-install.ps1 -Version 5.0.100-rc.2.20479.15 + .\dotnet-install.ps1 -Version 5.0.100 - displayName: "Install 5.0.100-rc.2.20479.15 SDK" + displayName: "Install 5.0.100" # NuGet Tool Installer # Acquires a specific version of NuGet from the internet or the tools cache and adds it to the PATH. Use this task to change the version of NuGet used in the NuGet tasks. From caa8d695c19db92ffb8a129ceb543798a51018e0 Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Tue, 10 Nov 2020 12:35:19 +0100 Subject: [PATCH 31/33] Bumped to version 0.54.0 --- src/Dotnet.Script.Core/Dotnet.Script.Core.csproj | 2 +- .../Dotnet.Script.DependencyModel.NuGet.csproj | 2 +- .../Dotnet.Script.DependencyModel.csproj | 2 +- src/Dotnet.Script/Dotnet.Script.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj b/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj index 2eb991c4..d9c52b50 100644 --- a/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj +++ b/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj @@ -2,7 +2,7 @@ A cross platform library allowing you to run C# (CSX) scripts with support for debugging and inline NuGet packages. Based on Roslyn. - 0.53.0 + 0.54.0 filipw netstandard2.0 Dotnet.Script.Core diff --git a/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj b/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj index 5a8baeb5..33576fa8 100644 --- a/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj +++ b/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj @@ -8,7 +8,7 @@ https://github.com/filipw/dotnet-script.git git script;csx;csharp;roslyn;nuget - 0.53.0 + 0.54.0 A MetadataReferenceResolver that allows inline nuget references to be specified in script(csx) files. dotnet-script dotnet-script diff --git a/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj b/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj index 33235f4f..02921389 100644 --- a/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj +++ b/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj @@ -11,7 +11,7 @@ https://github.com/filipw/dotnet-script.git git script;csx;csharp;roslyn;omnisharp - 0.53.0 + 0.54.0 latest diff --git a/src/Dotnet.Script/Dotnet.Script.csproj b/src/Dotnet.Script/Dotnet.Script.csproj index 06792762..e32181a4 100644 --- a/src/Dotnet.Script/Dotnet.Script.csproj +++ b/src/Dotnet.Script/Dotnet.Script.csproj @@ -1,7 +1,7 @@  Dotnet CLI tool allowing you to run C# (CSX) scripts. - 0.53.0 + 0.54.0 filipw Dotnet.Script net5.0;netcoreapp2.1;netcoreapp3.1 From b9ea04e5e63346e841c88f2598918bda95c326a9 Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Tue, 10 Nov 2020 12:44:09 +0100 Subject: [PATCH 32/33] pin 5.0.100 in global.json --- global.json.old => global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename global.json.old => global.json (62%) diff --git a/global.json.old b/global.json similarity index 62% rename from global.json.old rename to global.json index 245b5fb0..94eb6594 100644 --- a/global.json.old +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "3.1.102", + "version": "5.0.100", "rollForward": "latestFeature" } } From a4df919ed8c9e5c87012206463fe82f1e5d2552b Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Tue, 10 Nov 2020 13:38:55 +0100 Subject: [PATCH 33/33] Bumped version to 1.0.0 --- src/Dotnet.Script.Core/Dotnet.Script.Core.csproj | 2 +- .../Dotnet.Script.DependencyModel.NuGet.csproj | 2 +- .../Dotnet.Script.DependencyModel.csproj | 2 +- src/Dotnet.Script/Dotnet.Script.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj b/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj index d9c52b50..305e0b72 100644 --- a/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj +++ b/src/Dotnet.Script.Core/Dotnet.Script.Core.csproj @@ -2,7 +2,7 @@ A cross platform library allowing you to run C# (CSX) scripts with support for debugging and inline NuGet packages. Based on Roslyn. - 0.54.0 + 1.0.0 filipw netstandard2.0 Dotnet.Script.Core diff --git a/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj b/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj index 33576fa8..148a6ea0 100644 --- a/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj +++ b/src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj @@ -8,7 +8,7 @@ https://github.com/filipw/dotnet-script.git git script;csx;csharp;roslyn;nuget - 0.54.0 + 1.0.0 A MetadataReferenceResolver that allows inline nuget references to be specified in script(csx) files. dotnet-script dotnet-script diff --git a/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj b/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj index 02921389..ad38b324 100644 --- a/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj +++ b/src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj @@ -11,7 +11,7 @@ https://github.com/filipw/dotnet-script.git git script;csx;csharp;roslyn;omnisharp - 0.54.0 + 1.0.0 latest diff --git a/src/Dotnet.Script/Dotnet.Script.csproj b/src/Dotnet.Script/Dotnet.Script.csproj index e32181a4..ccde00a5 100644 --- a/src/Dotnet.Script/Dotnet.Script.csproj +++ b/src/Dotnet.Script/Dotnet.Script.csproj @@ -1,7 +1,7 @@  Dotnet CLI tool allowing you to run C# (CSX) scripts. - 0.54.0 + 1.0.0 filipw Dotnet.Script net5.0;netcoreapp2.1;netcoreapp3.1