Skip to content

Commit 7a77e51

Browse files
authored
Always use the latest version of the alternate package (#547)
1 parent 4d35660 commit 7a77e51

3 files changed

Lines changed: 44 additions & 7 deletions

File tree

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<Project>
33
<PropertyGroup>
4-
<Version>4.1.5</Version>
4+
<Version>4.1.6</Version>
55
<LangVersion>preview</LangVersion>
66
<NoWarn>NU1608</NoWarn>
77
<AssemblyVersion>1.0.0</AssemblyVersion>

src/PackageUpdate/Updater.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,8 @@ public static async Task Update(
314314
// Perform migration: update Include attribute and Version
315315
packageElement.SetAttributeValue("Include", alternatePackage.PackageId);
316316

317-
// Use the minimum version from the range if specified and greater than 0.0.0,
318-
// otherwise use the latest version we found
319-
var minVersion = alternatePackage.Range?.MinVersion;
320-
var targetVersion = minVersion != null && minVersion > new NuGetVersion(0, 0, 0)
321-
? minVersion
322-
: alternateMetadata.Identity.Version;
317+
// Always use the latest version of the alternate package
318+
var targetVersion = alternateMetadata.Identity.Version;
323319
packageElement.SetAttributeValue("Version", targetVersion.ToString());
324320

325321
Log.Information(

src/Tests/UpdaterTests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,47 @@ public async Task NoMigrationDoesNotUpdateCsprojFiles()
12561256
await Assert.That(csprojResult).IsEqualTo(originalCsproj);
12571257
}
12581258

1259+
[Test]
1260+
public async Task MigrationUsesLatestVersionNotMinVersion()
1261+
{
1262+
using var cache = new SourceCacheContext { RefreshMemoryCache = true };
1263+
var content =
1264+
"""
1265+
<Project>
1266+
<ItemGroup>
1267+
<PackageVersion Include="WindowsAzure.Storage" Version="9.3.3" />
1268+
</ItemGroup>
1269+
</Project>
1270+
""";
1271+
1272+
using var tempFile = await TempFile.CreateText(content);
1273+
1274+
await Updater.Update(cache, tempFile.Path, null);
1275+
1276+
var result = await File.ReadAllTextAsync(tempFile.Path);
1277+
var doc = XDocument.Parse(result);
1278+
1279+
var package = doc.Descendants("PackageVersion").Single();
1280+
var id = package.Attribute("Include")?.Value;
1281+
var version = package.Attribute("Version")?.Value;
1282+
1283+
// Should be migrated to the alternative package
1284+
await Assert.That(id).IsNotEqualTo("WindowsAzure.Storage");
1285+
1286+
// The migrated version should be the latest version of the alternate package,
1287+
// not the min version from the deprecation range
1288+
await Assert.That(NuGetVersion.TryParse(version, out var migratedVersion)).IsTrue();
1289+
1290+
var latestMetadata = await Updater.GetLatestVersion(
1291+
id!,
1292+
new NuGetVersion(0, 0, 0),
1293+
sources,
1294+
cache);
1295+
1296+
await Assert.That(latestMetadata).IsNotNull();
1297+
await Assert.That(migratedVersion!).IsEqualTo(latestMetadata!.Identity.Version);
1298+
}
1299+
12591300
[Test]
12601301
public async Task ConcurrentRepositoryReaderAccessDoesNotThrow()
12611302
{

0 commit comments

Comments
 (0)