Skip to content

Commit

Permalink
skip duplicated packages with the packageId as name
Browse files Browse the repository at this point in the history
  • Loading branch information
cwuethrich committed Mar 7, 2024
1 parent e2c7e08 commit 76265ee
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions source/Nuke.Tooling/NuGetPackageResolver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Maintainers of NUKE.
// Copyright 2023 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE

Expand Down 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 All @@ -239,10 +246,10 @@ string TryGetFromEnvironmentVariable()
string TryGetGlobalDirectoryFromConfig()
=> GetConfigFiles(packagesConfigFile)
.Select(x => new
{
File = x,
Setting = XDocument.Load(x).XPathSelectAttributeValues(".//add[@key='globalPackagesFolder']/@value").SingleOrDefault()
})
{
File = x,
Setting = XDocument.Load(x).XPathSelectAttributeValues(".//add[@key='globalPackagesFolder']/@value").SingleOrDefault()
})
.Where(x => x.Setting != null)
.Select(x => Path.IsPathRooted(x.Setting)
? x.Setting
Expand Down

0 comments on commit 76265ee

Please sign in to comment.