Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4f9dbd7

Browse filesBrowse files
authored
Merge branch 'master' into accept-encoding-gzip
2 parents e6ad3b8 + 8594f3e commit 4f9dbd7
Copy full SHA for 4f9dbd7

File tree

Expand file treeCollapse file tree

8 files changed

+114
-7
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+114
-7
lines changed

‎global.json

Copy file name to clipboard
+6Lines 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.Core/ScriptDownloader.cs

Copy file name to clipboard
100644100755
Expand all lines: src/Dotnet.Script.Core/ScriptDownloader.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public async Task<string> Download(string uri)
2424

2525
using (HttpContent content = response.Content)
2626
{
27-
var mediaType = content.Headers.ContentType.MediaType?.ToLowerInvariant().Trim();
27+
var mediaType = content.Headers.ContentType?.MediaType?.ToLowerInvariant().Trim();
2828
switch (mediaType)
2929
{
3030
case null:

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

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/Context/DotnetRestorer.cs
+9-3Lines changed: 9 additions & 3 deletions
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,13 +26,18 @@ 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}");
31-
if (exitcode != 0)
33+
34+
var commandPath = "dotnet";
35+
var commandArguments = $"restore \"{projectFileInfo.Path}\" -r {runtimeIdentifier} {packageSourcesArgument} {configFileArgument}";
36+
var commandResult = _commandRunner.Capture(commandPath, commandArguments, workingDirectory);
37+
if (commandResult.ExitCode != 0)
3238
{
3339
// We must throw here, otherwise we may incorrectly run with the old 'project.assets.json'
34-
throw new Exception($"Unable to restore packages from '{projectFileInfo.Path}'. Make sure that all script files contains valid NuGet references");
40+
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}");
3541
}
3642

3743
string CreatePackageSourcesArguments()
+80Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using Dotnet.Script.DependencyModel.Context;
2+
using Dotnet.Script.DependencyModel.Process;
3+
using Dotnet.Script.DependencyModel.ProjectSystem;
4+
using Dotnet.Script.Shared.Tests;
5+
using System;
6+
using System.IO;
7+
using Xunit;
8+
using Xunit.Abstractions;
9+
10+
namespace Dotnet.Script.Tests
11+
{
12+
public class DotnetRestorerTests
13+
{
14+
private PackageReference ValidPackageReferenceA => new PackageReference("Newtonsoft.Json", "12.0.3");
15+
private PackageReference ValidPackageReferenceB => new PackageReference("Moq", "4.14.5");
16+
17+
private PackageReference InvalidPackageReferenceA => new PackageReference("7c63e1f5-2248-ed31-9480-e4cb5ac322fe", "1.0.0");
18+
19+
public DotnetRestorerTests(ITestOutputHelper testOutputHelper)
20+
{
21+
testOutputHelper.Capture();
22+
}
23+
24+
[Fact]
25+
public void ShouldRestoreProjectPackageReferences()
26+
{
27+
using (var projectFolder = new DisposableFolder())
28+
{
29+
var pathToProjectFile = Path.Combine(projectFolder.Path, "script.csproj");
30+
31+
var projectFile = new ProjectFile();
32+
projectFile.PackageReferences.Add(ValidPackageReferenceA);
33+
projectFile.PackageReferences.Add(ValidPackageReferenceB);
34+
projectFile.Save(pathToProjectFile);
35+
36+
var projectFileInfo = new ProjectFileInfo(pathToProjectFile, string.Empty);
37+
38+
var logFactory = TestOutputHelper.CreateTestLogFactory();
39+
var commandRunner = new CommandRunner(logFactory);
40+
var restorer = new DotnetRestorer(commandRunner, logFactory);
41+
42+
var pathToProjectObjDirectory = Path.Combine(projectFolder.Path, "obj");
43+
44+
Assert.False(Directory.Exists(pathToProjectObjDirectory));
45+
46+
restorer.Restore(projectFileInfo, Array.Empty<string>());
47+
48+
Assert.True(Directory.Exists(pathToProjectObjDirectory));
49+
}
50+
}
51+
52+
[Fact]
53+
public void ShouldThrowExceptionOnRestoreError()
54+
{
55+
using (var projectFolder = new DisposableFolder())
56+
{
57+
var pathToProjectFile = Path.Combine(projectFolder.Path, "script.csproj");
58+
59+
var projectFile = new ProjectFile();
60+
projectFile.PackageReferences.Add(ValidPackageReferenceA);
61+
projectFile.PackageReferences.Add(InvalidPackageReferenceA);
62+
projectFile.PackageReferences.Add(ValidPackageReferenceB);
63+
projectFile.Save(pathToProjectFile);
64+
65+
var projectFileInfo = new ProjectFileInfo(pathToProjectFile, string.Empty);
66+
67+
var logFactory = TestOutputHelper.CreateTestLogFactory();
68+
var commandRunner = new CommandRunner(logFactory);
69+
var restorer = new DotnetRestorer(commandRunner, logFactory);
70+
71+
var exception = Assert.Throws<Exception>(() =>
72+
{
73+
restorer.Restore(projectFileInfo, Array.Empty<string>());
74+
});
75+
76+
Assert.Contains("NU1101", exception.Message); // unable to find package
77+
}
78+
}
79+
}
80+
}

‎src/Dotnet.Script.Tests/ScriptExecutionTests.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Tests/ScriptExecutionTests.cs
+10-1Lines 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

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Tests/ScriptTestRunner.cs
+2-2Lines 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

+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Console.WriteLine("Hello world!");
+5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.