Skip to content

Commit 5be9171

Browse files
committed
Fix single-dll fallback logic
1 parent 20d3322 commit 5be9171

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

Runner/Helpers/NuGetClient.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,27 +194,28 @@ public static bool IsPermissiveLicense(string? expression)
194194
x.Parts[2].EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
195195
.ToList();
196196

197-
// Prefer the DLL matching the package name, fall back if there's exactly one DLL
198-
var matchingEntries = allDllEntries
199-
.Where(x => x.Parts[2].Equals(expectedDll, StringComparison.OrdinalIgnoreCase))
200-
.ToList();
201-
202-
if (matchingEntries.Count == 0 && allDllEntries.Count == 1)
203-
matchingEntries = allDllEntries;
204-
205-
var tfmGroups = matchingEntries
197+
var tfmGroups = allDllEntries
206198
.GroupBy(x => x.Parts[1])
207-
.OrderByDescending(g => GetTfmPriority(g.Key))
199+
.Select(g =>
200+
{
201+
// Prefer the DLL matching the package name, fall back if there's exactly one DLL in the TFM
202+
var match = g.FirstOrDefault(x => x.Parts[2].Equals(expectedDll, StringComparison.OrdinalIgnoreCase));
203+
if (match.Entry is null && g.Count() == 1)
204+
match = g.First();
205+
return (Tfm: g.Key, Entry: match);
206+
})
207+
.Where(x => x.Entry.Entry is not null)
208+
.OrderByDescending(x => GetTfmPriority(x.Tfm))
208209
.ToList();
209210

210-
if (tfmGroups.Count == 0 || GetTfmPriority(tfmGroups[0].Key) < 0)
211+
if (tfmGroups.Count == 0 || GetTfmPriority(tfmGroups[0].Tfm) < 0)
211212
{
212213
File.Delete(nupkgPath);
213214
return (null, null);
214215
}
215216

216-
selectedTfm = tfmGroups[0].Key;
217-
var entry = tfmGroups[0].First();
217+
selectedTfm = tfmGroups[0].Tfm;
218+
var entry = tfmGroups[0].Entry;
218219

219220
string destPath = Path.Combine(extractDir, entry.Parts[2]);
220221
entry.Entry.ExtractToFile(destPath, overwrite: true);

0 commit comments

Comments
 (0)