Skip to content

Commit fba7d3c

Browse files
committed
Always compare both tfm AND rid for matching the target in a lock file
Fixes #90
1 parent a48da55 commit fba7d3c

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
* All nodes of the graph can now contain clickable links to their corresponding nuget.org page. This new behavior can be enabled by setting the `ChiselGraphIncludeLinks` MSBuild property to `true`. See the [ChiselGraphIncludeLinks](https://github.com/0xced/Chisel#chiselgraphincludelinks) documentation in the README for more information.
1010
* The graph now includes a title that defaults to `Dependency graph of $(MSBuildProjectName) ($(TargetFramework))`. See the [ChiselGraphTitle](https://github.com/0xced/Chisel#chiselgraphtitle) documentation in the README for more information.
1111
* The version numbers in the graph are now displayed with a `@` symbol instead of a `/` symbol when [ChiselGraphIncludeVersions](https://github.com/0xced/Chisel#chiselgraphincludeversions) is enabled.
12+
* Fixed a bug where Chisel could fail with ArgumentException: Multiple targets are matching … Reported by @codeguru42 in #90.
1213

1314
## [1.1.2][1.1.2] - 2025-02-17
1415

src/Chisel/LockFileExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ internal static class LockFileExtensions
1111
{
1212
public static (IReadOnlyDictionary<string, Package> Packages, IReadOnlyCollection<Package> Roots) ReadPackages(this LockFile lockFile, string tfm, string? rid, Predicate<Package>? filter = null)
1313
{
14+
var runtimeIdentifier = string.IsNullOrEmpty(rid) ? null : rid;
1415
var frameworks = lockFile.PackageSpec?.TargetFrameworks?.Where(e => e.TargetAlias == tfm).ToList() ?? [];
1516
var framework = frameworks.Count switch
1617
{
1718
0 => throw new ArgumentException($"Target framework \"{tfm}\" is not available in assets at \"{lockFile.Path}\" (JSON path: project.frameworks.*.targetAlias)", nameof(tfm)),
1819
1 => frameworks[0],
1920
_ => throw new ArgumentException($"Multiple target frameworks are matching \"{tfm}\" in assets at \"{lockFile.Path}\" (JSON path: project.frameworks.*.targetAlias)", nameof(tfm)),
2021
};
21-
var targets = lockFile.Targets.Where(e => e.TargetFramework == framework.FrameworkName && (string.IsNullOrEmpty(rid) || e.RuntimeIdentifier == rid)).ToList();
22+
var targets = lockFile.Targets.Where(e => e.TargetFramework == framework.FrameworkName && e.RuntimeIdentifier == runtimeIdentifier).ToList();
2223
// https://github.com/NuGet/NuGet.Client/blob/6.10.0.52/src/NuGet.Core/NuGet.ProjectModel/LockFile/LockFileTarget.cs#L17
23-
var targetId = framework.FrameworkName + (string.IsNullOrEmpty(rid) ? "" : $"/{rid}");
24+
var targetId = framework.FrameworkName + (string.IsNullOrEmpty(runtimeIdentifier) ? "" : $"/{runtimeIdentifier}");
2425
var target = targets.Count switch
2526
{
2627
0 => throw new ArgumentException($"Target \"{targetId}\" is not available in assets at \"{lockFile.Path}\" (JSON path: targets)", nameof(rid)),

tests/Chisel.Tests/DependencyGraphTest.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,14 @@ public async Task PollyGraphIgnoreGlob(bool includeLinks, [CombinatorialValues("
178178
await Verify(writer.ToString(), format == "graphviz" ? "gv" : "mmd").UseParameters(includeLinks, format);
179179
}
180180

181-
[Fact]
182-
public void ValidProjectVersion()
181+
[Theory]
182+
[InlineData("win-x64")]
183+
[InlineData("")]
184+
[InlineData(null)]
185+
public void ValidProjectVersion(string? rid)
183186
{
184187
var lockFile = new LockFileFormat().Read(GetAssetsPath("SqlClientGraph.json"));
185-
var (packages, roots) = lockFile.ReadPackages(tfm: "net8.0-windows", rid: "win-x64", package => package.IsProjectReference || SqlClientCopyLocalPackages.Contains(package.Name));
188+
var (packages, roots) = lockFile.ReadPackages(tfm: "net8.0-windows", rid: rid, package => package.IsProjectReference || SqlClientCopyLocalPackages.Contains(package.Name));
186189
var graph = new DependencyGraph(packages, roots, ignores: []);
187190

188191
graph.EnumerateUnsatisfiedProjectDependencies().Should().BeEmpty();

0 commit comments

Comments
 (0)