Skip to content

Commit f4ea82a

Browse files
authored
Merge pull request #573 from filipw/bugfix-working-directory
Ignore global.json in script folder
2 parents 6fc86f3 + a775643 commit f4ea82a

File tree

6 files changed

+29
-4
lines changed

6 files changed

+29
-4
lines changed

global.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sdk": {
3+
"version": "3.1.102",
4+
"rollForward": "latestFeature"
5+
}
6+
}

src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Dotnet.Script.DependencyModel.Process;
44
using Dotnet.Script.DependencyModel.ProjectSystem;
55
using System;
6+
using System.IO;
67
using System.Linq;
78

89
namespace Dotnet.Script.DependencyModel.Context
@@ -25,9 +26,12 @@ public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources)
2526
var packageSourcesArgument = CreatePackageSourcesArguments();
2627
var configFileArgument = CreateConfigFileArgument();
2728
var runtimeIdentifier = _scriptEnvironment.RuntimeIdentifier;
29+
var workingDirectory = Path.GetFullPath(Path.GetDirectoryName(projectFileInfo.Path));
30+
2831

2932
_logger.Debug($"Restoring {projectFileInfo.Path} using the dotnet cli. RuntimeIdentifier : {runtimeIdentifier} NugetConfigFile: {projectFileInfo.NuGetConfigFile}");
30-
var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument} {configFileArgument}");
33+
34+
var exitcode = _commandRunner.Execute("dotnet", $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument} {configFileArgument}", workingDirectory);
3135
if (exitcode != 0)
3236
{
3337
// We must throw here, otherwise we may incorrectly run with the old 'project.assets.json'

src/Dotnet.Script.Tests/ScriptExecutionTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,15 @@ public void ShouldHandleScriptWithTargetFrameworkInShebang()
456456
Assert.Contains("Hello world!", result.output);
457457
}
458458

459+
[Fact]
460+
public void ShouldIgnoreGlobalJsonInScriptFolder()
461+
{
462+
var fixture = "InvalidGlobalJson";
463+
var workingDirectory = Path.GetDirectoryName(TestPathUtils.GetPathToTestFixture(fixture));
464+
var result = ScriptTestRunner.Default.ExecuteFixture("InvalidGlobalJson", $"--no-cache", workingDirectory);
465+
Assert.Contains("Hello world!", result.output);
466+
}
467+
459468

460469
private static string CreateTestScript(string scriptFolder)
461470
{
@@ -470,7 +479,7 @@ private static string CreateTestScript(string scriptFolder)
470479

471480
private static void CreateTestPackage(string packageLibraryFolder)
472481
{
473-
ProcessHelper.RunAndCaptureOutput("dotnet", "new classlib -n NuGetConfigTestLibrary", packageLibraryFolder);
482+
ProcessHelper.RunAndCaptureOutput("dotnet", "new classlib -n NuGetConfigTestLibrary -f netstandard2.0", packageLibraryFolder);
474483
var projectFolder = Path.Combine(packageLibraryFolder, "NuGetConfigTestLibrary");
475484
ProcessHelper.RunAndCaptureOutput("dotnet", $"pack -o \"{Path.Combine(packageLibraryFolder, "packagePath")}\"", projectFolder);
476485
CreateNuGetConfig(packageLibraryFolder);

src/Dotnet.Script.Tests/ScriptTestRunner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public int ExecuteInProcess(string arguments = null)
3535
return Program.Main(arguments?.Split(" ") ?? Array.Empty<string>());
3636
}
3737

38-
public (string output, int exitCode) ExecuteFixture(string fixture, string arguments = null)
38+
public (string output, int exitCode) ExecuteFixture(string fixture, string arguments = null, string workingDirectory = null)
3939
{
4040
var pathToFixture = TestPathUtils.GetPathToTestFixture(fixture);
41-
var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments($"{pathToFixture} {arguments}"));
41+
var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments($"{pathToFixture} {arguments}"), workingDirectory);
4242
return result;
4343
}
4444

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Console.WriteLine("Hello world!");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "3.0.100"
4+
}
5+
}

0 commit comments

Comments
 (0)