Use correct nuget version normalized format (#9525)

* Use correct nuget version normalized format

* Change test accordingly

This matches nuget behavior
if restore with  `<PackageReference Include="global.tool.console.demo" Version="1.0.*" />` there is no warning
and if restore with `<PackageReference Include="global.tool.console.demo" Version="1.0.0" />` there is warning due to no exact 1.0.0 find
This commit is contained in:
William Li 2018-06-21 13:00:49 -07:00 committed by GitHub
parent 4757e52adb
commit 488edfad3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View file

@ -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"))));

View file

@ -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,