Skip to content

Ignore global.json in script folder #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "3.1.102",
"rollForward": "latestFeature"
}
}
6 changes: 5 additions & 1 deletion src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
11 changes: 10 additions & 1 deletion src/Dotnet.Script.Tests/ScriptExecutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed if you have the .Net 5 SDK installed since that version no longer defaults to netstandard2.0

var projectFolder = Path.Combine(packageLibraryFolder, "NuGetConfigTestLibrary");
ProcessHelper.RunAndCaptureOutput("dotnet", $"pack -o \"{Path.Combine(packageLibraryFolder, "packagePath")}\"", projectFolder);
CreateNuGetConfig(packageLibraryFolder);
Expand Down
4 changes: 2 additions & 2 deletions src/Dotnet.Script.Tests/ScriptTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public int ExecuteInProcess(string arguments = null)
return Program.Main(arguments?.Split(" ") ?? Array.Empty<string>());
}

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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Console.WriteLine("Hello world!");
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "3.0.100"
}
}