From 4cef2509ca6cb869cc4c4cac67dbd54bcf4fdde6 Mon Sep 17 00:00:00 2001 From: Mustafa Senoglu Date: Thu, 9 Jul 2026 14:29:38 +0300 Subject: [PATCH] fix: add support for Project and CentralTransitive dependency types in NuGet parser NuGet lockfiles can contain dependency types 'Project' and 'CentralTransitive' in addition to 'Direct' and 'Transitive'. The parser raised an exception for these unknown types, causing parsing to abort for valid NuGet lockfiles. This fix adds handling for: - Project: treated as direct dependency (is_direct=True) - CentralTransitive: treated as transitive dependency (is_direct=False) Also adds a test fixture with these dependency types. Fixes #5106 --- src/packagedcode/nuget.py | 4 +++ ...k.with_project_and_central_transitive.json | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/packagedcode/data/nuget/packages.lock.with_project_and_central_transitive.json diff --git a/src/packagedcode/nuget.py b/src/packagedcode/nuget.py index d0d7e110f2f..888a3286bce 100644 --- a/src/packagedcode/nuget.py +++ b/src/packagedcode/nuget.py @@ -237,6 +237,10 @@ def parse(cls, location, package_only=False): is_direct = True elif package_type == "Transitive": is_direct = False + elif package_type == "CentralTransitive": + is_direct = False + elif package_type == "Project": + is_direct = True else: raise Exception(f"Unknown package type: {package_type} for package {package_name} in {location}") diff --git a/tests/packagedcode/data/nuget/packages.lock.with_project_and_central_transitive.json b/tests/packagedcode/data/nuget/packages.lock.with_project_and_central_transitive.json new file mode 100644 index 00000000000..ce8c59cddfe --- /dev/null +++ b/tests/packagedcode/data/nuget/packages.lock.with_project_and_central_transitive.json @@ -0,0 +1,30 @@ +{ + "version": 2, + "dependencies": { + "net8.0": { + "Example.Direct": { + "type": "Direct", + "requested": "[1.0.0, )", + "resolved": "1.0.0", + "contentHash": "abc123==" + }, + "Example.Transitive": { + "type": "Transitive", + "resolved": "2.0.0", + "contentHash": "def456==" + }, + "Example.CentralTransitive": { + "type": "CentralTransitive", + "requested": "[3.0.0, )", + "resolved": "3.0.0", + "contentHash": "ghi789==" + }, + "example.project.reference": { + "type": "Project", + "dependencies": { + "Example.Direct": "[1.0.0, )" + } + } + } + } + }