Skip to content

Conversation

@JamieMagee
Copy link
Member

This extends on the support added in #1529 to support detection of NuGet packages in containers.

As an example, I ran

$ dotnet run --project src/Microsoft.ComponentDetection -- scan \
        --SourceDirectory ~/src/scratch/empty-directory/ \
        --Output scan-output \
        --DockerImagesToScan mcr.microsoft.com/dotnet/sdk:10.0-azurelinux3.0

Which gave the output here

@JamieMagee JamieMagee requested a review from a team as a code owner November 19, 2025 23:21
@github-actions
Copy link

github-actions bot commented Nov 19, 2025

👋 Hi! It looks like you modified some files in the Detectors folder.
You may need to bump the detector versions if any of the following scenarios apply:

  • The detector detects more or fewer components than before
  • The detector generates different parent/child graph relationships than before
  • The detector generates different devDependencies values than before

If none of the above scenarios apply, feel free to ignore this comment 🙂

@JamieMagee JamieMagee force-pushed the users/jamagee/nuget-components-in-containers branch 3 times, most recently from 6b57052 to 919da3a Compare November 19, 2025 23:23
Copilot finished reviewing on behalf of JamieMagee November 19, 2025 23:25
@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

❌ Patch coverage is 25.00000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.5%. Comparing base (32c05fb) to head (098b031).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...etectors/linux/Factories/DotnetComponentFactory.cs 8.3% 11 Missing ⚠️
...n.Detectors/linux/LinuxApplicationLayerDetector.cs 66.6% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1548     +/-   ##
=======================================
- Coverage   89.6%   89.5%   -0.1%     
=======================================
  Files        426     427      +1     
  Lines      36256   36270     +14     
  Branches    2260    2262      +2     
=======================================
+ Hits       32493   32497      +4     
- Misses      3300    3311     +11     
+ Partials     463     462      -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for detecting NuGet packages in container images by extending the Linux container detector functionality. It builds on the infrastructure added in PR #1529 to support additional package ecosystems in container scans.

  • Introduces DotnetComponentFactory to create NuGet components from Syft artifact output
  • Updates LinuxContainerDetector to include NuGet in supported categories and component types
  • Registers the new factory in the DI container for integration with the scanning pipeline

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs Registers DotnetComponentFactory in the DI container alongside other artifact component factories
src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs Adds NuGet to the detector's supported categories and component types
src/Microsoft.ComponentDetection.Detectors/linux/Factories/DotnetComponentFactory.cs New factory that creates NuGetComponent instances from dotnet artifact types detected by Syft
Comments suppressed due to low confidence (1)

src/Microsoft.ComponentDetection.Detectors/linux/Factories/DotnetComponentFactory.cs:37

  • The new DotnetComponentFactory should be added to the componentFactories list in the LinuxScannerTests test constructor to ensure it's included in test coverage. Currently, only LinuxComponentFactory, NpmComponentFactory, and PipComponentFactory are included in the tests. The factory should be added to match the pattern used for the other component factories.

This would ensure that tests like TestLinuxScanner_SupportsMultipleComponentTypes_Async can properly test dotnet artifacts alongside other component types.

public class DotnetComponentFactory : ArtifactComponentFactoryBase
{
    /// <inheritdoc/>
    public override IEnumerable<string> SupportedArtifactTypes => ["dotnet"];

    /// <inheritdoc/>
    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);
    }
}

@JamieMagee JamieMagee force-pushed the users/jamagee/nuget-components-in-containers branch from 919da3a to 098b031 Compare November 26, 2025 21:24
@JamieMagee JamieMagee enabled auto-merge (squash) November 26, 2025 22:06
@JamieMagee JamieMagee merged commit b88d00b into main Nov 26, 2025
27 of 28 checks passed
@JamieMagee JamieMagee deleted the users/jamagee/nuget-components-in-containers branch November 26, 2025 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants