Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<Project>
<PropertyGroup>
<Version>4.1.5</Version>
<Version>4.1.6</Version>
<LangVersion>preview</LangVersion>
<NoWarn>NU1608</NoWarn>
<AssemblyVersion>1.0.0</AssemblyVersion>
Expand Down
8 changes: 2 additions & 6 deletions src/PackageUpdate/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,8 @@ public static async Task Update(
// Perform migration: update Include attribute and Version
packageElement.SetAttributeValue("Include", alternatePackage.PackageId);

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

Log.Information(
Expand Down
41 changes: 41 additions & 0 deletions src/Tests/UpdaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,47 @@ public async Task NoMigrationDoesNotUpdateCsprojFiles()
await Assert.That(csprojResult).IsEqualTo(originalCsproj);
}

[Test]
public async Task MigrationUsesLatestVersionNotMinVersion()
{
using var cache = new SourceCacheContext { RefreshMemoryCache = true };
var content =
"""
<Project>
<ItemGroup>
<PackageVersion Include="WindowsAzure.Storage" Version="9.3.3" />
</ItemGroup>
</Project>
""";

using var tempFile = await TempFile.CreateText(content);

await Updater.Update(cache, tempFile.Path, null);

var result = await File.ReadAllTextAsync(tempFile.Path);
var doc = XDocument.Parse(result);

var package = doc.Descendants("PackageVersion").Single();
var id = package.Attribute("Include")?.Value;
var version = package.Attribute("Version")?.Value;

// Should be migrated to the alternative package
await Assert.That(id).IsNotEqualTo("WindowsAzure.Storage");

// The migrated version should be the latest version of the alternate package,
// not the min version from the deprecation range
await Assert.That(NuGetVersion.TryParse(version, out var migratedVersion)).IsTrue();

var latestMetadata = await Updater.GetLatestVersion(
id!,
new NuGetVersion(0, 0, 0),
sources,
cache);

await Assert.That(latestMetadata).IsNotNull();
await Assert.That(migratedVersion!).IsEqualTo(latestMetadata!.Identity.Version);
}

[Test]
public async Task ConcurrentRepositoryReaderAccessDoesNotThrow()
{
Expand Down
Loading