Repository navigation
Add regression test for exclude filter on non-normalized TFMs - #1131
Conversation
…ycloneDX#1126) With NuGet.ProjectModel 7.0.1, LockFileTarget.Name was normalized (e.g. "net48" -> ".NETFramework,Version=v4.8") and no longer matched the raw projectFileDependencyGroups keys. No package was marked as a direct reference, so --exclude-filter removed every package as an orphan. NuGet.ProjectModel 7.6.0 keeps the raw target name, which resolves the issue. Add a functional test using a real net48 project.assets.json to guard against a regression. The test fails against 7.0.1 with 0 of 10 components remaining. Signed-off-by: Magnus Lindhe <magnus@lindhe.org>
Question: should direct-reference matching stop depending on NuGet's target name format?This PR only adds a regression test. The bug itself was fixed by the NuGet.ProjectModel 7.0.1 → 7.6.0 update in 52ea46d. I'd like your advice on whether we should also change the matching logic. Background. .Where(f => f.FrameworkName == targetRuntime.Name)
So the current code works because of how 7.6.0 happens to read names. RID targets never match under either version. That has no visible effect today, because the plain target's copy of each package is the one kept. Proposed change: .Where(f => string.Equals(f.FrameworkName, targetFramework.TargetAlias, StringComparison.OrdinalIgnoreCase)
|| NuGetFramework.Parse(f.FrameworkName).Equals(targetRuntime.TargetFramework))
I have this change ready with a unit test that builds Questions:
This does not fix #1130, where RID-only packages are removed by |
Signed-off-by: Magnus Lindhe <magnus@lindhe.org>
|
Q1: yes, make the matching robust — and I can confirm the premise empirically. I ran your regression test against the same I also applied your proposed matching and tested it: at 7.0.1, where master gives 0 of 10, both tests pass and the full suite is 220 passed / 0 failed / 2 skipped; at 7.6.0 it is 220 / 0 / 2 on net8.0, net9.0 and net10.0. It removes the dependency on NuGet's name format and regresses nothing, so I would say it is worth doing. Q2: separate PR. This one is mergeable and valuable on its own. I have corrected my comment on #1126 and the related passage in #1133 — I had generalised from a Your RID observation also reproduces for me: adding Last thing: |
Signed-off-by: Michael Tsfoni <80639729+mtsfoni@users.noreply.github.com>
Updated [cyclonedx](https://github.com/CycloneDX/cyclonedx-dotnet) from 6.2.0 to 6.3.0. <details> <summary>Release notes</summary> _Sourced from [cyclonedx's releases](https://github.com/CycloneDX/cyclonedx-dotnet/releases)._ ## 6.3.0 ## Added - **NuGet purls for project references** (#1137, fixes #1136): combining `--set-nuget-purl` with `--include-project-references` generates missing project purls. Existing purls and custom BOM references are preserved, and dependency edges use the final references. ## Changed - **Development dependency scopes** (#1138): development dependencies and their development-only transitive dependencies are included by default with `scope="excluded"`. Packages shared with production runtime use remain `required`. - **`--exclude-dev` is deprecated but continues to filter**: it omits development-only and test-project-only packages while retaining packages shared with production runtime use. ## Fixed - **Assembly-name resolution** (#1128, fixes #917): resolve `$(RootNamespace)` in assembly names, including nested `$(MSBuildProjectName)` tokens. Missing, empty, or circular `$(AssemblyName)`-referencing namespaces fall back to the project filename. This is best-effort substitution, not full MSBuild evaluation. - **Exclusion filtering** (#1135, fixes #1133): `--exclude-filter` removes only packages it newly orphans; pre-existing orphans are retained. - **Target-framework regression coverage** (#1131, fixes #1126): verifies exclusion filtering for non-normalized target frameworks, including `net48`, `netstandard2.0`, `Net8.0`, and Windows-qualified TFMs. The underlying NuGet.ProjectModel 7.6.0 fix was already included in 6.2.1. ## Contributors Thanks to everyone who contributed code, tests, and issue reports to this release: - @MichaelKopfMkf — NuGet purls for project references (#1137, #1136). - @mtsfoni — development dependency scopes and compatible exclusion behavior (#1138). - @uo-uhbc — exclusion-filter orphan handling fix and reproduction (#1135, #1133). - @mgnslndh — regression coverage for exclusion filtering on non-normalized target frameworks (#1131). - @Eljees — root-namespace assembly-name resolution fix (#1128). - @TobiDimmel — reported the assembly-name property resolution issue (#917). - @jasonlhills — reported the exclusion-filter failure (#1126). ## 🎉 New Contributors A warm welcome and a big thank you to our first-time contributors: - @MichaelKopfMkf made their first contribution in [#1137](CycloneDX/cyclonedx-dotnet#1137). - @mgnslndh made their first contribution in [#1131](CycloneDX/cyclonedx-dotnet#1131). - @Eljees made their first contribution in [#1128](CycloneDX/cyclonedx-dotnet#1128). **Full changelog:** CycloneDX/cyclonedx-dotnet@v6.2.1...v6.3.0 ## 6.2.1 ## CycloneDX for .NET 6.2.1 This patch release fixes dependency resolution in multi-project solutions and hash computation for uncached NuGet packages. ### Fixed - **Resolve dependency ranges with multiple matching package versions** (#1113, fixes #1110) — solution scans no longer fail with `Sequence contains more than one matching element` when multiple merged package versions satisfy an unresolved NuGet dependency range. The BOM now retains a dependency edge to every matching component. - **Fix hash computation for uncached NuGet packages** (#1099) — reset the package stream before computing hashes when falling back to downloading an uncached `.nupkg`. ### Changed - Update .NET dependencies and CI tooling. - Upgrade Testcontainers to 4.16.0 to resolve SSH.NET security advisories in the E2E test infrastructure. This is a test-infrastructure update, not a runtime dependency change to the CLI. ### Documentation - Add a [best-practices guide](https://github.com/CycloneDX/cyclonedx-dotnet/blob/v6.2.1/docs/best-practices.md) covering root project targeting, restore-first workflows, and BOM metadata setup. ### Contributors Thanks to everyone who contributed to this release: - @LukasChristel — fix hash computation for uncached NuGet packages (#1099). - @michael-eberhard-skidata — report and reproduction for the multi-version dependency range failure (#1110). - @mtsfoni — dependency range resolution fix and regression coverage (#1113). **Full changelog:** CycloneDX/cyclonedx-dotnet@v6.2.0...v6.2.1 Commits viewable in [compare view](CycloneDX/cyclonedx-dotnet@v6.2.0...v6.3.0). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This PR adds a regession test for the issue described in #1126. A fix is strictly not necessary since a recent change from NuGet.ProjectModel 7.0.1 to 7.6.0 solved the issue.
With NuGet.ProjectModel 7.0.1, LockFileTarget.Name was normalized (e.g. "net48" -> ".NETFramework,Version=v4.8") and no longer matched the raw projectFileDependencyGroups keys. No package was marked as a direct reference, so --exclude-filter removed every package as an orphan.
NuGet.ProjectModel 7.6.0 keeps the raw target name, which resolves the issue. Add a functional test using a real net48 project.assets.json to guard against a regression.
The test fails against 7.0.1 with 0 of 10 components remaining.