CycloneDX.MSBuild 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package CycloneDX.MSBuild --version 1.0.2
                    
NuGet\Install-Package CycloneDX.MSBuild -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CycloneDX.MSBuild" Version="1.0.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CycloneDX.MSBuild" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="CycloneDX.MSBuild">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CycloneDX.MSBuild --version 1.0.2
                    
#r "nuget: CycloneDX.MSBuild, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CycloneDX.MSBuild@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CycloneDX.MSBuild&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=CycloneDX.MSBuild&version=1.0.2
                    
Install as a Cake Tool

CycloneDX.MSBuild

License NuGet CI Release

MSBuild targets for automatic CycloneDX SBOM (Software Bill of Materials) generation during build and pack operations. Seamlessly integrates the CycloneDX .NET tool into your build pipeline.

๐ŸŽฏ Overview

CycloneDX.MSBuild is a NuGet package inspired by Microsoft.Sbom.Targets that automatically generates CycloneDX SBOMs for your .NET projects. Simply add the package reference, and SBOMs are generated automatically during dotnet build or dotnet pack.

Why CycloneDX.MSBuild?

  • โœ… Zero Configuration: Works out of the box with sensible defaults
  • โœ… Security by Design: Runs in build context, no elevated permissions required
  • โœ… Multi-Target Support: Handles projects with multiple target frameworks
  • โœ… Flexible: Highly configurable via MSBuild properties
  • โœ… Standards Compliant: Generates CycloneDX 1.2-1.6 compatible SBOMs
  • โœ… Development Dependency: Doesn't pollute your dependency tree

๐Ÿš€ Quick Start

Installation

Add the package to your project:

dotnet add package CycloneDX.MSBuild

Or add it manually to your .csproj:

<ItemGroup>
  <PackageReference Include="CycloneDX.MSBuild" Version="1.0.0" PrivateAssets="all" />
</ItemGroup>

Build Your Project

dotnet build

That's it! Your SBOM will be generated at bin/Debug/net8.0/sbom.json (or your output directory).

๐Ÿ“‹ Features

Automatic SBOM Generation

SBOMs are generated automatically:

  • During Build: After successful compilation
  • During Pack: Included in NuGet packages under /sbom/
  • Multi-Targeting: Generates once per project, not per framework

Supported Output Formats

  • JSON (default) - CycloneDX JSON format
  • XML - CycloneDX XML format

CycloneDX Specification Versions

The tool automatically uses the latest CycloneDX specification version supported by the installed tool version (typically 1.6).

โš™๏ธ Configuration

All configuration is done via MSBuild properties. Set them in your .csproj, Directory.Build.props, or command line.

Core Settings

Enable/Disable SBOM Generation
<PropertyGroup>
  
  <GenerateCycloneDxSbom>false</GenerateCycloneDxSbom>
</PropertyGroup>
Error Handling
<PropertyGroup>
  
  <CycloneDxContinueOnError>false</CycloneDxContinueOnError>
</PropertyGroup>

Output Configuration

Output Format
<PropertyGroup>
  
  <CycloneDxOutputFormat>xml</CycloneDxOutputFormat>
</PropertyGroup>
Output Location
<PropertyGroup>
  
  <CycloneDxOutputDirectory>$(MSBuildProjectDirectory)/sbom/</CycloneDxOutputDirectory>

  
  <CycloneDxOutputFilename>software-bom</CycloneDxOutputFilename>
</PropertyGroup>

Advanced Options

Exclude Dependencies
<PropertyGroup>
  
  <CycloneDxExcludeDev>true</CycloneDxExcludeDev>

  
  <CycloneDxExcludeTestProjects>true</CycloneDxExcludeTestProjects>
</PropertyGroup>
Serial Number Control
<PropertyGroup>
  
  <CycloneDxDisableSerialNumber>true</CycloneDxDisableSerialNumber>
</PropertyGroup>
Import Metadata Template
<PropertyGroup>
  
  <CycloneDxImportMetadataPath>$(MSBuildProjectDirectory)/sbom-metadata.xml</CycloneDxImportMetadataPath>
</PropertyGroup>

The metadata template allows you to provide project-specific details that will be included in the generated SBOM. This is useful for adding custom component information, licenses, and descriptions to your SBOM.

Example sbom-metadata.xml:

Note: CycloneDX.MSBuild supports metadata templates using CycloneDX schema versions 1.2 through 1.6. You may use any supported version, but 1.6 is recommended for new projects.

<?xml version="1.0" encoding="utf-8"?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.6">
  <metadata>
    <component type="application" bom-ref="pkg:nuget/YourProject@1.0.0">
      <name>YourProject</name>
      <version>1.0.0</version>
      <description>
        <![CDATA[Your project description]]>
      </description>
      <licenses>
        <license>
          <name>Apache License 2.0</name>
          <id>Apache-2.0</id>
        </license>
      </licenses>
      <purl>pkg:nuget/YourProject@1.0.0</purl>
    </component>
  </metadata>
</bom>
GitHub License Resolution
<PropertyGroup>
  
  <CycloneDxEnableGitHubLicenses>true</CycloneDxEnableGitHubLicenses>

  
  <CycloneDxGitHubUsername>your-username</CycloneDxGitHubUsername>
  <CycloneDxGitHubToken>ghp_yourtoken</CycloneDxGitHubToken>
</PropertyGroup>

Tool Version

<PropertyGroup>
  
  <CycloneDxToolVersion>5.5.0</CycloneDxToolVersion>
</PropertyGroup>

๐Ÿ“ฆ NuGet Package Integration

When you run dotnet pack, the generated SBOM is automatically included in the NuGet package under the /sbom/ directory.

dotnet pack

Consumers of your NuGet package can inspect the SBOM:

# Extract and view
unzip -q MyPackage.1.0.0.nupkg -d extracted
cat extracted/sbom/sbom.json

๐Ÿ—๏ธ Architecture

MSBuild Integration

CycloneDX.MSBuild uses MSBuild's extensibility hooks:

  1. .props file - Defines configurable properties with defaults
  2. .targets file - Implements build targets for SBOM generation
  3. buildMultiTargeting/ - Special handling for multi-target projects

Target Execution Order

Build โ†’ ValidateCycloneDxConfiguration โ†’ EnsureCycloneDxToolInstalled โ†’ GenerateCycloneDxSbom

Security by Design

  • Sandboxed Execution: Runs in build context without elevated privileges
  • Input Validation: All properties are validated before use
  • Fail-Safe Defaults: Continues build on errors by default
  • No Code Execution: Only executes vetted CycloneDX tool
  • Dependency Pinning: Explicit tool version control

Clean Code Principles

  • Separation of Concerns: Configuration (.props) separated from logic (.targets)
  • Single Responsibility: Each target has one clear purpose
  • DRY: Reusable property groups
  • Consistent Naming: CycloneDx* prefix for all properties
  • Comprehensive Documentation: XML comments for all properties

๐Ÿงช Testing

The repository includes integration tests for various scenarios:

tests/
โ”œโ”€โ”€ SimpleProject/          # Basic single-target project
โ”œโ”€โ”€ MultiTargetProject/     # Multi-targeting (.NET 6, 8, Standard 2.0)
โ””โ”€โ”€ DisabledProject/        # Project with SBOM generation disabled

๐Ÿ”„ Versioning

This project uses automated semantic versioning with:

  • MinVer: Automatic version calculation from Git tags
  • semantic-release: Automated releases, changelogs, and NuGet publishing

All commits must follow Conventional Commits format.

๐Ÿ“– For detailed information, see VERSIONING.md

๐Ÿš€ CI/CD Pipeline

This project includes a comprehensive CI/CD pipeline with automated testing and publishing:

Continuous Integration (CI)

Runs on all pull requests and feature branches:

  • โœ… Multi-platform testing (Ubuntu, Windows, macOS)
  • โœ… Multi-version .NET testing (.NET 6.0 and 8.0)
  • โœ… Code quality checks (formatting, package validation)
  • โœ… Dependency security scanning (vulnerable and deprecated packages)
  • โœ… Build artifact generation

Continuous Deployment (CD)

Runs on pushes to main, master, beta, or alpha branches:

  1. Build & Test - Full test suite execution
  2. Package Validation - NuGet package quality checks
  3. Semantic Release - Automatic version determination from commits
  4. NuGet Publishing - Automatic publishing to NuGet.org
  5. GitHub Release - Automated release notes and changelog

Setting up Automated Publishing

To enable automated NuGet publishing:

  1. Get a NuGet API key from NuGet.org
  2. Add it as a GitHub secret named NUGET_API_KEY
  3. The release workflow will automatically publish on version bumps

๐Ÿ“– For detailed CI/CD documentation, see .github/workflows/README.md

๐Ÿ”ง Development

Project Structure

CycloneDX.MSBuild/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ CycloneDX.MSBuild/
โ”‚       โ”œโ”€โ”€ build/
โ”‚       โ”‚   โ”œโ”€โ”€ CycloneDX.MSBuild.props      # Configuration properties
โ”‚       โ”‚   โ””โ”€โ”€ CycloneDX.MSBuild.targets    # Build integration
โ”‚       โ”œโ”€โ”€ buildMultiTargeting/             # Multi-target support
โ”‚       โ””โ”€โ”€ CycloneDX.MSBuild.csproj         # Package definition
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ Integration.Tests/
โ””โ”€โ”€ README.md

Building Locally

# Build the package
dotnet build src/CycloneDX.MSBuild/CycloneDX.MSBuild.csproj

# Pack the package
dotnet pack src/CycloneDX.MSBuild/CycloneDX.MSBuild.csproj

# Test with local projects
dotnet build tests/Integration.Tests/SimpleProject/SimpleProject.csproj

๐Ÿ“š Comparison with Microsoft.Sbom.Targets

Feature Microsoft.Sbom.Targets CycloneDX.MSBuild
SBOM Format SPDX 2.2 CycloneDX 1.2-1.6
Tool Microsoft.Sbom.Tool (embedded) CycloneDX .NET tool (local tool, installed on demand)
Build Support โœ… โœ…
Pack Support โœ… โœ…
Publish Support โŒ โณ Planned
Multi-Targeting โœ… โœ…
Development Dependency โœ… โœ…

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.

Guidelines

  • Follow existing code style and architecture
  • Maintain security by design principles
  • Add tests for new features
  • Update documentation

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ“ž Support


Made with โค๏ธ for Software Supply Chain Security

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.1 804 12/10/2025
1.3.0 1,857 12/3/2025
1.2.1 752 12/3/2025
1.2.0 668 12/1/2025
1.1.0 786 12/1/2025
1.0.2 680 12/1/2025

Initial release:
     - Automatic SBOM generation during build
     - Support for dotnet build and dotnet pack
     - Configurable output format (JSON/XML)
     - Integration with CycloneDX .NET tool