From 098b031447f54a17d31eab30854d010e096d5d4a Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Wed, 19 Nov 2025 15:16:22 -0800 Subject: [PATCH] Add support for NuGet components in containers --- .../linux/Factories/DotnetComponentFactory.cs | 32 +++++++++++++++++++ .../linux/LinuxApplicationLayerDetector.cs | 5 +-- .../Extensions/ServiceCollectionExtensions.cs | 1 + 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/Microsoft.ComponentDetection.Detectors/linux/Factories/DotnetComponentFactory.cs diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/Factories/DotnetComponentFactory.cs b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/DotnetComponentFactory.cs new file mode 100644 index 000000000..df75a8353 --- /dev/null +++ b/src/Microsoft.ComponentDetection.Detectors/linux/Factories/DotnetComponentFactory.cs @@ -0,0 +1,32 @@ +namespace Microsoft.ComponentDetection.Detectors.Linux.Factories; + +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using Microsoft.ComponentDetection.Contracts.TypedComponent; +using Microsoft.ComponentDetection.Detectors.Linux.Contracts; + +/// +/// Factory for creating instances from .NET package artifacts. +/// +public class DotnetComponentFactory : ArtifactComponentFactoryBase +{ + /// + public override IEnumerable SupportedArtifactTypes => ["dotnet"]; + + /// + public override TypedComponent? CreateComponent([NotNull] ArtifactElement artifact, [NotNull] Distro distro) + { + if (string.IsNullOrWhiteSpace(artifact.Name) || string.IsNullOrWhiteSpace(artifact.Version)) + { + return null; + } + + var author = GetAuthorFromArtifact(artifact); + var authors = string.IsNullOrWhiteSpace(author) ? null : new[] { author }; + + return new NuGetComponent( + name: artifact.Name, + version: artifact.Version, + authors: authors); + } +} diff --git a/src/Microsoft.ComponentDetection.Detectors/linux/LinuxApplicationLayerDetector.cs b/src/Microsoft.ComponentDetection.Detectors/linux/LinuxApplicationLayerDetector.cs index 322192af3..0244564b3 100644 --- a/src/Microsoft.ComponentDetection.Detectors/linux/LinuxApplicationLayerDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/linux/LinuxApplicationLayerDetector.cs @@ -30,13 +30,14 @@ ILogger logger Enum.GetName(typeof(DetectorClass), DetectorClass.Linux), Enum.GetName(typeof(DetectorClass), DetectorClass.Npm), Enum.GetName(typeof(DetectorClass), DetectorClass.Pip), + Enum.GetName(typeof(DetectorClass), DetectorClass.NuGet), ]; /// public new IEnumerable SupportedComponentTypes => - [ComponentType.Linux, ComponentType.Npm, ComponentType.Pip]; + [ComponentType.Linux, ComponentType.Npm, ComponentType.Pip, ComponentType.NuGet]; /// protected override ISet GetEnabledComponentTypes() => - new HashSet { ComponentType.Linux, ComponentType.Npm, ComponentType.Pip }; + new HashSet { ComponentType.Linux, ComponentType.Npm, ComponentType.Pip, ComponentType.NuGet }; } diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs b/src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs index 19814e2c3..5c881b798 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs @@ -105,6 +105,7 @@ public static IServiceCollection AddComponentDetection(this IServiceCollection s services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton();