Skip to content

Commit c1f0528

Browse files
Fix NuGet restore behavior for unspecified version and add corresponding tests
1 parent 829de22 commit c1f0528

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

CSharpInteractive.Tests/Integration/NuGetTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,25 @@ public void ShouldSupportRestoreWhenScript()
5454
result.ExitCode.ShouldBe(0, result.ToString());
5555
}
5656

57+
[Fact]
58+
public void ShouldRestoreLatestVersionWhenNoVersionSpecified()
59+
{
60+
// Given
61+
var nuget = Composition.Shared.Root.NuGet;
62+
63+
// When
64+
var version = nuget.Value
65+
.Restore(new NuGetRestoreSettings("Pure.DI")
66+
.WithHideWarningsAndErrors(true)
67+
.WithNoCache(true))
68+
.Where(i => i.Name == "Pure.DI")
69+
.Select(i => i.NuGetVersion)
70+
.Max();
71+
72+
// Then
73+
version.ShouldNotBeNull();
74+
version.ShouldBeGreaterThan(new NuGetVersion(1, 0, 0));
75+
}
76+
5777
private static string CreateTempDirectory() => Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()[..4]);
5878
}

CSharpInteractive.Tests/Integration/ScriptRunTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public void ShouldSupportInfo()
188188
[InlineData("nuget: IoC.Container, 1.3.6", "//1")]
189189
[InlineData("nuget:IoC.Container,1.3.6", "//1")]
190190
[InlineData("nuget: IoC.Container, [1.3.6, 2)", "//1")]
191+
[InlineData("nuget: IoC.Container", "//1")]
191192
public void ShouldSupportNuGetRestore(string package, string name)
192193
{
193194
// Given

CSharpInteractive/Core/NuGetRestoreService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public bool TryRestore(NuGetRestoreSettings settings, out string projectAssetsJs
6969
{
7070
LibraryRange = new LibraryRange(
7171
settings.PackageId,
72-
settings.VersionRange ?? VersionRange.All,
72+
settings.VersionRange ?? VersionRange.Parse("*"),
7373
LibraryDependencyTarget.Package),
7474
IncludeType = LibraryIncludeFlags.All
7575
};

0 commit comments

Comments
 (0)