diff --git a/global.json b/global.json new file mode 100644 index 00000000..245b5fb0 --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "3.1.102", + "rollForward": "latestFeature" + } +} diff --git a/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs b/src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs index 3ae1cedc..bfacf1ca 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.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}"); + + var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -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.Tests/ScriptExecutionTests.cs b/src/Dotnet.Script.Tests/ScriptExecutionTests.cs index e8a99471..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) { @@ -470,7 +479,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); 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" + } +}