From 488edfad3f4b23ae4b2800332059097fff8d0444 Mon Sep 17 00:00:00 2001 From: William Li Date: Thu, 21 Jun 2018 13:00:49 -0700 Subject: [PATCH] Use correct nuget version normalized format (#9525) * Use correct nuget version normalized format * 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 --- .../ToolPackage/ToolPackageInstaller.cs | 2 +- .../ToolPackageInstallerTests.cs | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/dotnet/ToolPackage/ToolPackageInstaller.cs b/src/dotnet/ToolPackage/ToolPackageInstaller.cs index aa63ae8c7..17d5ad80b 100644 --- a/src/dotnet/ToolPackage/ToolPackageInstaller.cs +++ b/src/dotnet/ToolPackage/ToolPackageInstaller.cs @@ -154,7 +154,7 @@ namespace Microsoft.DotNet.ToolPackage 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 1b4dcadbd..6b90ff3fb 100644 --- a/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs +++ b/test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs @@ -598,7 +598,7 @@ namespace Microsoft.DotNet.ToolPackage.Tests var package = installer.InstallPackage( packageId: TestPackageId, - versionRange: VersionRange.Parse("1.0.*"), + versionRange: VersionRange.Parse("1.0.0"), targetFramework: _testTargetframework, nugetConfig: nugetConfigPath); @@ -612,6 +612,31 @@ namespace Microsoft.DotNet.ToolPackage.Tests 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,