From 3fc2a1afa79de62b7a94f51619e70c67d71dd47b Mon Sep 17 00:00:00 2001 From: William Li Date: Wed, 20 Jun 2018 18:00:41 -0700 Subject: [PATCH 1/2] Use correct nuget version normalized format --- .../ToolPackage/ToolPackageInstaller.cs | 2 +- .../ToolPackageInstallerTests.cs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/dotnet/ToolPackage/ToolPackageInstaller.cs b/src/dotnet/ToolPackage/ToolPackageInstaller.cs index aa63ae8c72..17d5ad80b7 100644 --- a/src/dotnet/ToolPackage/ToolPackageInstaller.cs +++ b/src/dotnet/ToolPackage/ToolPackageInstaller.cs @@ -154,7 +154,7 @@ private FilePath CreateTempProject(PackageId packageId, new XElement("PackageReference", new XAttribute("Include", packageId.ToString()), new XAttribute("Version", - versionRange?.ToString("S", new VersionRangeFormatter()) ?? "*"))), // nuget will restore latest stable for * + versionRange?.ToString("N", new VersionRangeFormatter()) ?? "*"))), // nuget will restore latest stable for * and format N is the normalization format new XElement(("Import"), new XAttribute("Project", "Sdk.targets"), new XAttribute("Sdk", "Microsoft.NET.Sdk")))); diff --git a/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs b/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs index 1b4dcadbd5..e9baaf7404 100644 --- a/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs +++ b/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs @@ -612,6 +612,31 @@ public void GivenANuGetDiagnosticMessageItShouldNotContainTheTempProject() package.Uninstall(); } + [Theory] + [InlineData(false)] + [InlineData(true)] + // repro https://github.com/dotnet/cli/issues/9409 + public void GivenAComplexVersionRangeInstallSucceeds(bool testMockBehaviorIsInSync) + { + var nugetConfigPath = WriteNugetConfigFileToPointToTheFeed(); + var emptySource = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + Directory.CreateDirectory(emptySource); + + var (store, installer, reporter, fileSystem) = Setup( + useMock: testMockBehaviorIsInSync, + feeds: GetMockFeedsForSource(emptySource)); + + var package = installer.InstallPackage( + packageId: TestPackageId, + versionRange: VersionRange.Parse("1.0.0-rc*"), + targetFramework: _testTargetframework, + nugetConfig: nugetConfigPath, additionalFeeds: new[] { emptySource }); + + AssertPackageInstall(reporter, fileSystem, package, store); + + package.Uninstall(); + } + private static void AssertPackageInstall( BufferedReporter reporter, IFileSystem fileSystem, From cac452b38b133052231d9eade6847b4df86c1ff9 Mon Sep 17 00:00:00 2001 From: William Li Date: Thu, 21 Jun 2018 10:35:59 -0700 Subject: [PATCH 2/2] Change test accordingly This matches nuget behavior if restore with `` there is no warning and if restore with `` there is warning due to no exact 1.0.0 find --- .../ToolPackageInstallerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs b/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs index e9baaf7404..6b90ff3fb7 100644 --- a/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs +++ b/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs @@ -598,7 +598,7 @@ public void GivenANuGetDiagnosticMessageItShouldNotContainTheTempProject() var package = installer.InstallPackage( packageId: TestPackageId, - versionRange: VersionRange.Parse("1.0.*"), + versionRange: VersionRange.Parse("1.0.0"), targetFramework: _testTargetframework, nugetConfig: nugetConfigPath);