diff --git a/src/NuGetUtility/ReferencedPackagesReader/ReferencedPackageReader.cs b/src/NuGetUtility/ReferencedPackagesReader/ReferencedPackageReader.cs index 14ec2611..1a4cec64 100644 --- a/src/NuGetUtility/ReferencedPackagesReader/ReferencedPackageReader.cs +++ b/src/NuGetUtility/ReferencedPackagesReader/ReferencedPackageReader.cs @@ -57,10 +57,16 @@ private bool TryGetInstalledPackagesFromAssetsFile(bool includeTransitive, if (targetFramework is not null) { - ILockFileTarget target = (assetsFile.Targets?.FirstOrDefault(t => t.TargetFramework.Equals(targetFramework))) ?? + IEnumerable matchingTargets = assetsFile.Targets!.Where(t => t.TargetFramework.Equals(targetFramework)); + if (!matchingTargets.Any()) + { throw new ReferencedPackageReaderException($"Target framework {targetFramework} not found."); + } - referencedLibraries.AddRange(GetReferencedLibrariesForTarget(includeTransitive, assetsFile, target)); + foreach (ILockFileTarget target in matchingTargets) + { + referencedLibraries.AddRange(GetReferencedLibrariesForTarget(includeTransitive, assetsFile, target)); + } } else {