From a354c09e0db85b2997522797ac770156fd0ec63e Mon Sep 17 00:00:00 2001 From: Bernhard Richter Date: Mon, 10 Aug 2020 17:24:26 +0200 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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" } }