From 18a3dd60b5ea4b2644839ca8e6caa6209c362155 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Thu, 12 Jan 2017 18:23:35 -0800 Subject: [PATCH] Fixing an issue where packages with a filter but no match were not being migrated as is, instead they were being dropped. --- .../MigratePackageDependenciesAndToolsRule.cs | 24 +++++++++---------- ...WantToMigratePackagesToTheirLTSVersions.cs | 12 ++++++++++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs index a16dc0a0f..3c07316e0 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesAndToolsRule.cs @@ -291,21 +291,19 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules { var possibleVersions = possibleMappings.Select(p => VersionRange.Parse(p.Key.Version)); var matchVersion = possibleVersions.FirstOrDefault(p => p.Satisfies(minRange)); - if (matchVersion == null) + if (matchVersion != null) { - return null; + var dependencyInfo = possibleMappings.First(c => + c.Key.Version.Equals(matchVersion.OriginalString, StringComparison.OrdinalIgnoreCase)).Value; + + if (dependencyInfo == null) + { + return null; + } + + name = dependencyInfo.Name; + version = dependencyInfo.Version; } - - var dependencyInfo = possibleMappings.First(c => - c.Key.Version.Equals(matchVersion.OriginalString, StringComparison.OrdinalIgnoreCase)).Value; - - if (dependencyInfo == null) - { - return null; - } - - name = dependencyInfo.Name; - version = dependencyInfo.Version; } return new PackageDependencyInfo diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackagesToTheirLTSVersions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackagesToTheirLTSVersions.cs index ba790fd4b..c8ab19dde 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackagesToTheirLTSVersions.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackagesToTheirLTSVersions.cs @@ -24,6 +24,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests ValidatePackageMigration(sourcePackageName, sourceVersion, targetPackageName, targetVersion); } + [Theory] + [InlineData("NETStandard.Library", "1.6.2-*", "NETStandard.Library", "1.6.2-*")] + [InlineData("System.Text.Encodings.Web", "4.4.0-*", "System.Text.Encodings.Web", "4.4.0-*")] + public void ItDoesNotDropDependenciesThatDoNotHaveAMatchingVersionInTheMapping( + string sourcePackageName, + string sourceVersion, + string targetPackageName, + string targetVersion) + { + ValidatePackageMigration(sourcePackageName, sourceVersion, targetPackageName, targetVersion); + } + [Theory] [InlineData("Microsoft.AspNetCore.Antiforgery", "1.0.0", "Microsoft.AspNetCore.Antiforgery", ConstantPackageVersions.AspNetLTSPackagesVersion)] [InlineData("Microsoft.AspNetCore.Mvc", "1.0.0", "Microsoft.AspNetCore.Mvc", ConstantPackageVersions.AspNetLTSPackagesVersion)]