Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid duplicate dotnetcli #1355

Closed
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
14 changes: 14 additions & 0 deletions source/Nuke.Tooling.Tests/NuGetPackageResolverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ public void TestGetGlobalInstalledPackage()
result.Version.OriginalVersion.Should().Be(XunitConsolePackageVersion);
}

[Fact]
public void TestGetGlobalInstalledPackageWithDuplicateNupkg()
{
var result = NuGetPackageResolver.GetGlobalInstalledPackage("coverlet.console", version: null, packagesConfigFile: null);
// Null is the result as well, but it is inconclusive :(
if (result != null)
{
result.Should().NotBeNull();
result.Id.Should().Be("coverlet.console");
result.File.Name.Should().EndWith("nupkg");
// Do not check version as it is not deterministic
}
}

[Fact]
public void TestGetLocalInstalledPackageViaProjectFile()
{
Expand Down
7 changes: 7 additions & 0 deletions source/Nuke.Tooling/NuGetPackageResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ private static IEnumerable<InstalledPackage> GetDependentPackages(InstalledPacka
.OrderByDescending(x => x.Version)
.ToList();

if (candidatePackages.GroupBy(g => g.Version).Any(p => p.Count() > 1))
// skip duplicated packages with the packageId as name
candidatePackages = candidatePackages
.GroupBy(g => g.Version)
.SelectMany(g => g.Count() <= 1 ? g : g.Where(p => !p.File.NameWithoutExtension.EqualsOrdinalIgnoreCase(packageId)))
.ToList();

return versionRange == null
? candidatePackages.FirstOrDefault()
: candidatePackages.SingleOrDefault(x => x.Version == versionRange.FindBestMatch(candidatePackages.Select(y => y.Version)));
Expand Down
Loading