From 78476ce4bb2fb031144937a3d5b81badd47e23ee Mon Sep 17 00:00:00 2001 From: Joel Verhagen Date: Fri, 8 Jul 2016 12:09:10 -0700 Subject: [PATCH] Use min of version range for Project K dependencies (matches UWP project.json) Fixes https://github.com/NuGet/Home/issues/3070 Fixes https://github.com/NuGet/Home/issues/3095 --- .../ProjectSystems/ProjectKNuGetProject.cs | 12 +++++++--- .../ProjectKNuGetProjectTests.cs | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/NuGet.Clients/PackageManagement.VisualStudio/ProjectSystems/ProjectKNuGetProject.cs b/src/NuGet.Clients/PackageManagement.VisualStudio/ProjectSystems/ProjectKNuGetProject.cs index ff553d12548..489dd4715af 100644 --- a/src/NuGet.Clients/PackageManagement.VisualStudio/ProjectSystems/ProjectKNuGetProject.cs +++ b/src/NuGet.Clients/PackageManagement.VisualStudio/ProjectSystems/ProjectKNuGetProject.cs @@ -139,9 +139,15 @@ public override async Task> GetInstalledPackagesAs var moniker = item as INuGetPackageMoniker; if (moniker != null) { - identity = new PackageIdentity( - moniker.Id, - NuGetVersion.Parse(moniker.Version)); + // As with build integrated projects (UWP project.json), treat the version as a + // version range and use the minimum version of that range. Eventually, this + // method should return VersionRange instances, not NuGetVersion so that the + // UI can express the full project.json intent. This improvement is tracked + // here: https://github.com/NuGet/Home/issues/3101 + var versionRange = VersionRange.Parse(moniker.Version); + var version = versionRange.MinVersion; + + identity = new PackageIdentity(moniker.Id, version); } else { diff --git a/test/NuGet.Clients.Tests/NuGet.PackageManagement.VisualStudio.Test/ProjectKNuGetProjectTests.cs b/test/NuGet.Clients.Tests/NuGet.PackageManagement.VisualStudio.Test/ProjectKNuGetProjectTests.cs index 8855814e72b..2cbecaa76de 100644 --- a/test/NuGet.Clients.Tests/NuGet.PackageManagement.VisualStudio.Test/ProjectKNuGetProjectTests.cs +++ b/test/NuGet.Clients.Tests/NuGet.PackageManagement.VisualStudio.Test/ProjectKNuGetProjectTests.cs @@ -20,6 +20,29 @@ namespace NuGet.PackageManagement.VisualStudio.Test { public class ProjectKNuGetProjectTests { + [Fact] + public async Task ProjectKNuGetProject_WithVersionRange_GetInstalledPackagesAsync() + { + // Arrange + using (var testDirectory = TestFileSystemUtility.CreateRandomTestFolder()) + { + var tc = new TestContext(testDirectory); + + tc.PackageManager + .Setup(x => x.GetInstalledPackagesAsync(It.IsAny())) + .ReturnsAsync(new[] { new NuGetPackageMoniker { Id = "foo", Version = "1.0.0-*" } }); + + // Act + var actual = await tc.Target.GetInstalledPackagesAsync(CancellationToken.None); + + // Assert + Assert.Equal(1, actual.Count()); + var packageReference = actual.First(); + Assert.Equal("foo", packageReference.PackageIdentity.Id); + Assert.Equal(NuGetVersion.Parse("1.0.0--"), packageReference.PackageIdentity.Version); + } + } + [Fact] public async Task ProjectKNuGetProject_WithPackageTypes_InstallPackageAsync() {