Skip to content

Commit 08ba73d

Browse files
gustavoaca1997sfoslundvpatakottuvpatakottudependabot[bot]
authored
Add a SBOM Generation Task (#674)
* Experimenting with dotnet * Add comments * Make the Sbom.Targets project to build. * Add all arguments to GenerateSBOMTask (#1) Co-authored-by: vpatakottu <[email protected]> * Add call to the SBOM API from GenerateSbomTask#Execute (#2) * Start implementing Execute * Make SBOM Targets test target .NET 8 only. * Make the Component Path not required. * Build the current project in test, and check that the manifest was generated. * Ad a few comments for TODOs. * Validate and Sanitize Arguments (#3) * Validate arguments * ignore case for enum conversion * create method for manifestinfo --------- Co-authored-by: vpatakottu <[email protected]> * Add tests for Generate SBOM Task (#4) * Add more tests for GenerateSbomTask.Execute logic * Add SBOM Validation to the Generate SBOM Task tests. * Add a utility method that validates the SBOM being generated during tests * Make more tests use the new utility validator method * Pass sbom specification during tests * Refactor GenerateSbomTask tests to be parametrized through the SBOM Specification * Fix typo * Add an abstract method for the Sbom Specification of the AbstractGenerateSbomTaskTests * Address PR suggestions * Made fields internal instead of private in AbstractGenerateSbomTaskTests * Add unit tests for GenerateSbomTask inputs (#6) * add unit tests for GenerateSbomTask inputs * remove console print * Addressing feedback * addressing feedback and adding more tests' --------- Co-authored-by: vpatakottu <[email protected]> * Add additional unit tests for valid cases (#7) * add additional unit tests for valid cases * address feedback and add few more cases --------- Co-authored-by: vpatakottu <[email protected]> * Merging Varshita's branch into our feature branch (#12) * setting up imports * Add reference to local Nuget package, for testing purposes * rename targets and props, export them to the build folder * Fix test project * Fix Targets file to include props * Manually adding the Sources Providers that support ProviderType.Packages * Manually add the missing classes for SBOM generation * Add MSBuild properties to our Props file (#8) * Use MSBuild/.NET props for default values of the Generate SBOM task. * Remove hardcoded path from the Targets * Add default value to props file for SbomGenerationManifestDirPath * Add final ManifestDirPath to SbomGenerationResult. * Fix typo * Change Summary comment for ManifestDirPath * include sbom files in user's nuget packages (#11) Co-authored-by: vpatakottu <[email protected]> * Make the task target .net 8 and .net 6 (#13) * Remove unrooted checks (#14) * Downgrade Microsoft.Extensions.Hosting back to 7.0.1 * Remove LocalNuget configuration * Stop tracking nuspec file * Remove unnecessary comments. * Remove reference to Microsoft.Sbom.Targets Nuget * Apply suggestions from the linter and PR comments. --------- Co-authored-by: vpatakottu <[email protected]> Co-authored-by: vpatakottu <[email protected]> * Fix ubuntu tests (#16) * add users/gustavoca/net-sdk-sbom-tool branch to PR pipelines * Fix Ubuntu tests for Targets project * Update feature branch (#17) * build(deps): bump actions/checkout from 4.1.1 to 4.1.6 (#574) Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.1 to 4.1.6. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@b4ffde6...a5ac7e5) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump github/codeql-action from 3.24.3 to 3.25.8 (#591) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.24.3 to 3.25.8. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@3796146...2e230e8) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add missing header to AbstractGenerateSbomTaskTests (#598) * Create template tool task (#600) * create template tool task * Make the tests successfully run * Include the SBOM CLI Tool to the .NET Framework package folder. * refactor code a little and address feedback @microsoft-github-policy-service agree company="Microsoft" --------- Co-authored-by: vpatakottu <[email protected]> Co-authored-by: gustavoaca1997 <[email protected]> * Run the Github build also for feature branches. * Implement SBOM CLI ToolTask (#607) * implement ToolTask * addressing feedback * addressing feedback pt. 2 --------- Co-authored-by: vpatakottu <[email protected]> * Update System.Text.Json * Stop importing the props twice when referencing the Nuget package (#612) * Add tests for the MSBuild Full version of the Generate SBOM task (#613) * Bring changes from feautre branch * Make the Targets.Tests project also target .NET Framework * Remove props file * Implement tests for MSBuild Full version of the task * Simplify how the CLI tool is called from the tests. * Add test for file being in use. * Test the output of the ToolTask. * Change the name of AbstractGenerateSBomTaskInputTests to AbstractGenerateSbomTaskInputTests * Include .NET Framework output in Sbom_Generation_Succeeds_For_Null_Verbosity * Update src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs Co-authored-by: Dave Tryon <[email protected]> * Skip tests that are failing due to known issues * Add debug messages for the test pipeline * Fix .net core tests * Target .NET Framework only on Windows * Remove unnecessary comment. * Update default Verbosity. * Address comments. * Change name of AbstractGenerateSbomTaskInputTests * Address PR Comments --------- Co-authored-by: Dave Tryon <[email protected]> * Update NuGet Package Format and Surface Errors (#619) * update nuget package format and surface errors * simplify sbom output * update targets to use SbomPath output var for ToolTask * fix bad merge * append manifest folder name for manifestdirpath * add path.combine and property checks * append platform version * create ManifestDirPath if needed * temporarily comment out * remove manifestdirpath logic for now * use path.combine and full path --------- Co-authored-by: vpatakottu <[email protected]> * Add README for Microsoft.Sbom.Targets project (#651) * Adding readme * add code quotes --------- Co-authored-by: vpatakottu <[email protected]> * Workaround for generating a SBOM manifest at the root level of the Nuget Package (#656) * Add buildMultiTargeting folder to the Nuget package * Unzip and Zip again for including the SBOM into the Nuget package. * Append GUID to the temporary unzipped folder. * Use Path.Combine for Unzip and Nupkg paths (#663) * Add E2E tests for Microsoft.Sbom.Targets project (#658) * add base setup for tests * updates to test * cleanup * Add more tests * update package version * cleanup * mini fix for copying sample project * add unloading step * create separate project for E2E tests * cleanup * rearrange method * cleanup * check for platform * try with locator * disable analyzers for sample project --------- Co-authored-by: vpatakottu <[email protected]> * Remove GenerateSBOMTest project (#673) * Remove GenerateSBOMTest project * Remove N/A comment * Add ContinueOnError=ErrorAndContinue to the ZipDirectory, GenerateSBOM and Unzip (#672) * User/gustavoca/update with main (#675) * Bump Component Detection version (#624) * Bump Component Detection version * Bump NuGet Config and Framework versions * Raise dependabot PR limit (#629) * build(deps): bump stefanzweifel/git-auto-commit-action (#552) Bumps [stefanzweifel/git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action) from 5.0.0 to 5.0.1. - [Release notes](https://github.com/stefanzweifel/git-auto-commit-action/releases) - [Changelog](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/CHANGELOG.md) - [Commits](stefanzweifel/git-auto-commit-action@8756aa0...8621497) --- updated-dependencies: - dependency-name: stefanzweifel/git-auto-commit-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Dave Tryon <[email protected]> * build(deps): bump Microsoft.NET.Test.Sdk from 17.7.2 to 17.10.0 (#630) Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.7.2 to 17.10.0. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](microsoft/vstest@v17.7.2...v17.10.0) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump MSTest.TestAdapter from 3.1.1 to 3.5.0 (#644) Bumps [MSTest.TestAdapter](https://github.com/microsoft/testfx) from 3.1.1 to 3.5.0. - [Release notes](https://github.com/microsoft/testfx/releases) - [Changelog](https://github.com/microsoft/testfx/blob/main/docs/Changelog.md) - [Commits](microsoft/testfx@v3.1.1...v3.5.0) --- updated-dependencies: - dependency-name: MSTest.TestAdapter dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump Spectre.Console.Cli from 0.48.0 to 0.49.1 (#637) Bumps [Spectre.Console.Cli](https://github.com/spectreconsole/spectre.console) from 0.48.0 to 0.49.1. - [Release notes](https://github.com/spectreconsole/spectre.console/releases) - [Commits](spectreconsole/spectre.console@0.48.0...0.49.1) --- updated-dependencies: - dependency-name: Spectre.Console.Cli dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump github/codeql-action from 3.25.12 to 3.25.15 (#625) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.25.12 to 3.25.15. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@4fa2a79...afb54ba) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump MSTest.TestFramework from 3.1.1 to 3.5.0 (#642) Bumps [MSTest.TestFramework](https://github.com/microsoft/testfx) from 3.1.1 to 3.5.0. - [Release notes](https://github.com/microsoft/testfx/releases) - [Changelog](https://github.com/microsoft/testfx/blob/main/docs/Changelog.md) - [Commits](microsoft/testfx@v3.1.1...v3.5.0) --- updated-dependencies: - dependency-name: MSTest.TestFramework dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump Microsoft.VisualStudio.Threading.Analyzers (#638) Bumps [Microsoft.VisualStudio.Threading.Analyzers](https://github.com/microsoft/vs-threading) from 17.7.30 to 17.10.48. - [Release notes](https://github.com/microsoft/vs-threading/releases) - [Commits](microsoft/vs-threading@v17.7.30...v17.10.48) --- updated-dependencies: - dependency-name: Microsoft.VisualStudio.Threading.Analyzers dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump github/codeql-action from 3.25.15 to 3.26.0 (#654) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.25.15 to 3.26.0. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@afb54ba...eb055d7) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump MSTest.TestAdapter from 3.5.0 to 3.5.1 (#653) Bumps [MSTest.TestAdapter](https://github.com/microsoft/testfx) from 3.5.0 to 3.5.1. - [Release notes](https://github.com/microsoft/testfx/releases) - [Changelog](https://github.com/microsoft/testfx/blob/main/docs/Changelog.md) - [Commits](microsoft/testfx@v3.5.0...v3.5.1) --- updated-dependencies: - dependency-name: MSTest.TestAdapter dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sarah Oslund <[email protected]> * build(deps): bump MSTest.TestFramework from 3.5.0 to 3.5.1 (#652) Bumps [MSTest.TestFramework](https://github.com/microsoft/testfx) from 3.5.0 to 3.5.1. - [Release notes](https://github.com/microsoft/testfx/releases) - [Changelog](https://github.com/microsoft/testfx/blob/main/docs/Changelog.md) - [Commits](microsoft/testfx@v3.5.0...v3.5.1) --- updated-dependencies: - dependency-name: MSTest.TestFramework dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sarah Oslund <[email protected]> * build(deps): bump Moq from 4.17.2 to 4.20.70 (#640) Bumps [Moq](https://github.com/moq/moq) from 4.17.2 to 4.20.70. - [Release notes](https://github.com/moq/moq/releases) - [Changelog](https://github.com/devlooped/moq/blob/main/CHANGELOG.md) - [Commits](moq/moq.spikes@v4.17.2...v4.20.70) --- updated-dependencies: - dependency-name: Moq dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump coverlet.collector from 6.0.0 to 6.0.2 (#641) Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 6.0.0 to 6.0.2. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](coverlet-coverage/coverlet@v6.0.0...v6.0.2) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump StyleCop.Analyzers (#636) Bumps [StyleCop.Analyzers](https://github.com/DotNetAnalyzers/StyleCopAnalyzers) from 1.2.0-beta.507 to 1.2.0-beta.556. - [Release notes](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/releases) - [Changelog](https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/KnownChanges.md) - [Commits](DotNetAnalyzers/StyleCopAnalyzers@1.2.0-beta.507...1.2.0-beta.556) --- updated-dependencies: - dependency-name: StyleCop.Analyzers dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump Microsoft.SourceLink.GitHub from 1.1.1 to 8.0.0 (#645) Bumps [Microsoft.SourceLink.GitHub](https://github.com/dotnet/sourcelink) from 1.1.1 to 8.0.0. - [Release notes](https://github.com/dotnet/sourcelink/releases) - [Commits](dotnet/sourcelink@1.1.1...8.0.0) --- updated-dependencies: - dependency-name: Microsoft.SourceLink.GitHub dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump MinVer from 4.3.0 to 5.0.0 (#634) Bumps [MinVer](https://github.com/adamralph/minver) from 4.3.0 to 5.0.0. - [Changelog](https://github.com/adamralph/minver/blob/main/CHANGELOG.md) - [Commits](adamralph/minver@4.3.0...5.0.0) --- updated-dependencies: - dependency-name: MinVer dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump Microsoft.Extensions.Http, Microsoft.Extensions.Logging.Abstractions and Microsoft.Extensions.DependencyInjection (#649) Bumps [Microsoft.Extensions.Http](https://github.com/dotnet/runtime), [Microsoft.Extensions.Logging.Abstractions](https://github.com/dotnet/runtime) and [Microsoft.Extensions.DependencyInjection](https://github.com/dotnet/runtime). These dependencies needed to be updated together. Updates `Microsoft.Extensions.Http` from 7.0.0 to 8.0.0 - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](dotnet/runtime@v7.0.0...v8.0.0) Updates `Microsoft.Extensions.Logging.Abstractions` from 7.0.1 to 8.0.0 - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](dotnet/runtime@v7.0.1...v8.0.0) Updates `Microsoft.Extensions.DependencyInjection` from 7.0.0 to 8.0.0 - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](dotnet/runtime@v7.0.0...v8.0.0) --- updated-dependencies: - dependency-name: Microsoft.Extensions.Http dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Microsoft.Extensions.Logging.Abstractions dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Microsoft.Extensions.DependencyInjection dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump Microsoft.Extensions.Logging.Abstractions and Microsoft.Extensions.DependencyInjection.Abstractions (#650) Bumps [Microsoft.Extensions.Logging.Abstractions](https://github.com/dotnet/runtime) and [Microsoft.Extensions.DependencyInjection.Abstractions](https://github.com/dotnet/runtime). These dependencies needed to be updated together. Updates `Microsoft.Extensions.Logging.Abstractions` from 7.0.1 to 8.0.1 - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](dotnet/runtime@v7.0.1...v8.0.1) Updates `Microsoft.Extensions.DependencyInjection.Abstractions` from 8.0.0 to 8.0.1 - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](dotnet/runtime@v8.0.0...v8.0.1) --- updated-dependencies: - dependency-name: Microsoft.Extensions.Logging.Abstractions dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Microsoft.Extensions.DependencyInjection.Abstractions dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump Scrutor from 4.2.0 to 4.2.2 (#646) Bumps [Scrutor](https://github.com/khellang/Scrutor) from 4.2.0 to 4.2.2. - [Release notes](https://github.com/khellang/Scrutor/releases) - [Commits](khellang/Scrutor@v4.2.0...v4.2.2) --- updated-dependencies: - dependency-name: Scrutor dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Fix tests * Bump Microsoft.Extensions.Hosting --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: José Renan <[email protected]> Co-authored-by: Dave Tryon <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sarah Oslund <[email protected]> * Update README * Address Feedback (#679) * Address feedback and remove SbomPath * remove whitespace * remove comment --------- Co-authored-by: vpatakottu <[email protected]> * address more feedback (#682) Co-authored-by: vpatakottu <[email protected]> * Pack each project separately (#681) * Pack each project separately * Remove extra dotnet apck * Inspect the content of the Nuget package instead of extracting to disk during e2e tests. * User/gustavoca/dont extract e2e tests (#684) * Inspect the content of the Nuget package instead of extracting to disk during e2e tests. * Remove extra changes in Directory.Packages.Props * Remove instance of Newtonsoft.Json * Remove not needed Message * Revert "Remove instance of Newtonsoft.Json" This reverts commit 52329d4. --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Sarah Oslund <[email protected]> Co-authored-by: vpatakottu <[email protected]> Co-authored-by: vpatakottu <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Dave Tryon <[email protected]> Co-authored-by: José Renan <[email protected]>
1 parent a029b40 commit 08ba73d

22 files changed

+2171
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ PublishScripts/
189189

190190
# NuGet Packages
191191
*.nupkg
192+
*.nuspec
192193
# NuGet Symbol Packages
193194
*.snupkg
194195
# The packages folder can be ignored because of Package Restore

Directory.Packages.props

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
1515
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
1616
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
17+
<PackageVersion Include="Microsoft.Build" Version="17.3.2" />
18+
<PackageVersion Include="Microsoft.Build.Framework" Version="17.10.4" />
19+
<PackageVersion Include="Microsoft.Build.Locator" Version="1.7.8" />
20+
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.10.4" />
21+
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
1722
<PackageVersion Include="MSTest.TestAdapter" Version="3.5.2" />
1823
<PackageVersion Include="MSTest.TestFramework" Version="3.5.2" />
1924
<PackageVersion Include="Microsoft.ComponentDetection.Common" Version="$(ComponentDetectionPackageVersion)" />
@@ -22,7 +27,7 @@
2227
<PackageVersion Include="Microsoft.ComponentDetection.Orchestrator" Version="$(ComponentDetectionPackageVersion)" />
2328
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
2429
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
25-
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
30+
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
2631
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
2732
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
2833
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
@@ -44,6 +49,7 @@
4449
<PackageVersion Include="Serilog.Sinks.Map" Version="1.0.2" />
4550
<PackageVersion Include="Spectre.Console.Cli" Version="0.49.1" />
4651
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
52+
<PackageVersion Include="System.IO.Compression" Version="4.3.0" />
4753
<PackageVersion Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
4854
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
4955
<PackageVersion Include="System.Memory" Version="4.5.5" />

Microsoft.Sbom.sln

+18
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Sbom.Extensions.D
4949
EndProject
5050
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Sbom.Extensions.DependencyInjection.Tests", "test\Microsoft.Sbom.Extensions.DependencyInjection.Tests\Microsoft.Sbom.Extensions.DependencyInjection.Tests.csproj", "{EE4E2E03-7B4C-46E5-B9D2-89E84A18D787}"
5151
EndProject
52+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Sbom.Targets", "src\Microsoft.Sbom.Targets\Microsoft.Sbom.Targets.csproj", "{E6C3C851-EEA0-466E-BA36-73ED85F13EEA}"
53+
EndProject
54+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Sbom.Targets.Tests", "test\Microsoft.Sbom.Targets.Tests\Microsoft.Sbom.Targets.Tests.csproj", "{E31B914C-F24B-4DC8-ACC7-CAEA952563B8}"
55+
EndProject
5256
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Sbom.Tool.Tests", "test\Microsoft.Sbom.Tool.Tests\Microsoft.Sbom.Tool.Tests.csproj", "{FC5A9799-7C44-4BFA-BA22-55DCAF1A1B9F}"
5357
EndProject
58+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Sbom.Targets.E2E.Tests", "test\Microsoft.Sbom.Targets.E2E.Tests\Microsoft.Sbom.Targets.E2E.Tests.csproj", "{3FDE7800-F61F-4C45-93AB-648A4C7979C7}"
59+
EndProject
5460
Global
5561
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5662
Debug|Any CPU = Debug|Any CPU
@@ -109,10 +115,22 @@ Global
109115
{EE4E2E03-7B4C-46E5-B9D2-89E84A18D787}.Debug|Any CPU.Build.0 = Debug|Any CPU
110116
{EE4E2E03-7B4C-46E5-B9D2-89E84A18D787}.Release|Any CPU.ActiveCfg = Release|Any CPU
111117
{EE4E2E03-7B4C-46E5-B9D2-89E84A18D787}.Release|Any CPU.Build.0 = Release|Any CPU
118+
{E6C3C851-EEA0-466E-BA36-73ED85F13EEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
119+
{E6C3C851-EEA0-466E-BA36-73ED85F13EEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
120+
{E6C3C851-EEA0-466E-BA36-73ED85F13EEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
121+
{E6C3C851-EEA0-466E-BA36-73ED85F13EEA}.Release|Any CPU.Build.0 = Release|Any CPU
122+
{E31B914C-F24B-4DC8-ACC7-CAEA952563B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
123+
{E31B914C-F24B-4DC8-ACC7-CAEA952563B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
124+
{E31B914C-F24B-4DC8-ACC7-CAEA952563B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
125+
{E31B914C-F24B-4DC8-ACC7-CAEA952563B8}.Release|Any CPU.Build.0 = Release|Any CPU
112126
{FC5A9799-7C44-4BFA-BA22-55DCAF1A1B9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
113127
{FC5A9799-7C44-4BFA-BA22-55DCAF1A1B9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
114128
{FC5A9799-7C44-4BFA-BA22-55DCAF1A1B9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
115129
{FC5A9799-7C44-4BFA-BA22-55DCAF1A1B9F}.Release|Any CPU.Build.0 = Release|Any CPU
130+
{3FDE7800-F61F-4C45-93AB-648A4C7979C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
131+
{3FDE7800-F61F-4C45-93AB-648A4C7979C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
132+
{3FDE7800-F61F-4C45-93AB-648A4C7979C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
133+
{3FDE7800-F61F-4C45-93AB-648A4C7979C7}.Release|Any CPU.Build.0 = Release|Any CPU
116134
EndGlobalSection
117135
GlobalSection(SolutionProperties) = preSolution
118136
HideSolutionNode = FALSE

nuget.config

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<packageSources>
44
<clear />
55
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
66
</packageSources>
7-
</configuration>
7+
</configuration>

pipelines/sbom-tool-main-build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ extends:
105105
]
106106
condition: and(succeeded(), startswith(variables['Build.SourceBranch'], 'refs/tags/'))
107107

108-
- powershell: 'dotnet pack Microsoft.Sbom.sln -c $(BuildConfiguration) --no-restore --no-build -o $(Build.ArtifactStagingDirectory)/nuget --include-symbols -p:SymbolPackageFormat=snupkg'
108+
- powershell: 'Get-ChildItem -Recurse -Filter *.csproj -Path src | ForEach-Object { dotnet pack $_.FullName -c $(BuildConfiguration) --no-restore --no-build -o $(Build.ArtifactStagingDirectory)/nuget --include-symbols -p:SymbolPackageFormat=snupkg }'
109109
displayName: 'Pack NuGet package'
110110

111111
- task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@3
+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.Sbom.Targets;
5+
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Diagnostics.Tracing;
9+
using Microsoft.Build.Framework;
10+
11+
/// <summary>
12+
/// This partial class defines and sanitizes the arguments that will be passed
13+
/// into the SBOM API and CLI tool for generation.
14+
/// </summary>
15+
public partial class GenerateSbom
16+
{
17+
/// <summary>
18+
/// Gets or sets the path to the drop directory for which the SBOM will be generated.
19+
/// </summary>
20+
[Required]
21+
public string BuildDropPath { get; set; }
22+
23+
/// <summary>
24+
/// Gets or sets the supplier of the package the SBOM represents.
25+
/// </summary>
26+
[Required]
27+
public string PackageSupplier { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the name of the package the SBOM represents.
31+
/// </summary>
32+
[Required]
33+
public string PackageName { get; set; }
34+
35+
/// <summary>
36+
/// Gets or sets the version of the package the SBOM represents.
37+
/// </summary>
38+
[Required]
39+
public string PackageVersion { get; set; }
40+
41+
/// <summary>
42+
/// Gets or sets the base path of the SBOM namespace uri.
43+
/// </summary>
44+
[Required]
45+
public string NamespaceBaseUri { get; set; }
46+
47+
/// <summary>
48+
/// Gets or sets the path to the directory containing build components and package information.
49+
/// For example, path to a .csproj or packages.config file.
50+
/// </summary>
51+
public string BuildComponentPath { get; set; }
52+
53+
/// <summary>
54+
/// Gets or sets a unique URI part that will be appended to NamespaceBaseUri.
55+
/// </summary>
56+
public string NamespaceUriUniquePart { get; set; }
57+
58+
/// <summary>
59+
/// Gets or sets the path to a file containing a list of external SBOMs that will be appended to the
60+
/// SBOM that is being generated.
61+
/// </summary>
62+
public string ExternalDocumentListFile { get; set; }
63+
64+
/// <summary>
65+
/// Indicates whether licensing information will be fetched for detected packages.
66+
/// </summary>
67+
public bool FetchLicenseInformation { get; set; }
68+
69+
/// <summary>
70+
/// Indicates whether to parse licensing and supplier information from a packages metadata file.
71+
/// </summary>
72+
public bool EnablePackageMetadataParsing { get; set; }
73+
74+
/// <summary>
75+
/// Gets or sets the verbosity level for logging output.
76+
/// </summary>
77+
public string Verbosity { get; set; }
78+
79+
/// <summary>
80+
/// Gets or sets a list of names and versions of the manifest format being used.
81+
/// </summary>
82+
public string ManifestInfo { get; set; }
83+
84+
/// <summary>
85+
/// Indicates whether the previously generated SBOM manifest directory should be deleted
86+
/// before generating a new SBOM in the directory specified by ManifestDirPath.
87+
/// Defaults to true.
88+
/// </summary>
89+
public bool DeleteManifestDirIfPresent { get; set; } = true;
90+
91+
/// <summary>
92+
/// Gets or sets the path where the SBOM will be generated. For now, this property
93+
/// will be unset as the _manifest directory is intended to be at the root of a NuGet package
94+
/// specified by BuildDropPath.
95+
/// </summary>
96+
public string ManifestDirPath { get; set; }
97+
98+
/// <summary>
99+
/// Gets or sets the path to the SBOM CLI tool
100+
/// </summary>
101+
public string SbomToolPath { get; set; }
102+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.Sbom.Targets;
5+
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Diagnostics.Tracing;
9+
using System.IO;
10+
using Microsoft.Build.Framework;
11+
using Microsoft.Build.Utilities;
12+
using Microsoft.Extensions.DependencyInjection;
13+
using Microsoft.Extensions.Hosting;
14+
using Microsoft.Sbom.Api.Manifest.ManifestConfigHandlers;
15+
using Microsoft.Sbom.Api.Metadata;
16+
using Microsoft.Sbom.Api.Providers;
17+
using Microsoft.Sbom.Api.Providers.ExternalDocumentReferenceProviders;
18+
using Microsoft.Sbom.Api.Providers.FilesProviders;
19+
using Microsoft.Sbom.Api.Providers.PackagesProviders;
20+
using Microsoft.Sbom.Contracts;
21+
using Microsoft.Sbom.Contracts.Entities;
22+
using Microsoft.Sbom.Contracts.Interfaces;
23+
using Microsoft.Sbom.Extensions;
24+
using Microsoft.Sbom.Extensions.DependencyInjection;
25+
using Microsoft.Sbom.Parsers.Spdx22SbomParser;
26+
27+
/// <summary>
28+
/// MSBuild task for generating SBOMs from build output.
29+
/// </summary>
30+
public partial class GenerateSbom : Task
31+
{
32+
private ISBOMGenerator Generator { get; set; }
33+
34+
/// <summary>
35+
/// Constructor for the GenerateSbomTask.
36+
/// </summary>
37+
public GenerateSbom()
38+
{
39+
var host = Host.CreateDefaultBuilder()
40+
.ConfigureServices((host, services) =>
41+
services
42+
.AddSbomTool()
43+
/* Manually adding some dependencies since `AddSbomTool()` does not add them when
44+
* running the MSBuild Task from another project.
45+
*/
46+
.AddSingleton<ISourcesProvider, SBOMPackagesProvider>()
47+
.AddSingleton<ISourcesProvider, CGExternalDocumentReferenceProvider>()
48+
.AddSingleton<ISourcesProvider, DirectoryTraversingFileToJsonProvider>()
49+
.AddSingleton<ISourcesProvider, ExternalDocumentReferenceFileProvider>()
50+
.AddSingleton<ISourcesProvider, ExternalDocumentReferenceProvider>()
51+
.AddSingleton<ISourcesProvider, FileListBasedFileToJsonProvider>()
52+
.AddSingleton<ISourcesProvider, SbomFileBasedFileToJsonProvider>()
53+
.AddSingleton<ISourcesProvider, CGScannedExternalDocumentReferenceFileProvider>()
54+
.AddSingleton<ISourcesProvider, CGScannedPackagesProvider>()
55+
.AddSingleton<IAlgorithmNames, AlgorithmNames>()
56+
.AddSingleton<IManifestGenerator, Generator>()
57+
.AddSingleton<IMetadataProvider, LocalMetadataProvider>()
58+
.AddSingleton<IMetadataProvider, SBOMApiMetadataProvider>()
59+
.AddSingleton<IManifestInterface, Validator>()
60+
.AddSingleton<IManifestConfigHandler, SPDX22ManifestConfigHandler>())
61+
.Build();
62+
this.Generator = host.Services.GetRequiredService<ISBOMGenerator>();
63+
}
64+
65+
/// <inheritdoc/>
66+
public override bool Execute()
67+
{
68+
try
69+
{
70+
// Validate required args and args that take paths as input.
71+
if (!ValidateAndSanitizeRequiredParams() || !ValidateAndSanitizeNamespaceUriUniquePart())
72+
{
73+
return false;
74+
}
75+
76+
// Set other configurations. The GenerateSBOMAsync() already sanitizes and checks for
77+
// a valid namespace URI and generates a random guid for NamespaceUriUniquePart if
78+
// one is not provided.
79+
var sbomMetadata = new SBOMMetadata
80+
{
81+
PackageSupplier = this.PackageSupplier,
82+
PackageName = this.PackageName,
83+
PackageVersion = this.PackageVersion,
84+
};
85+
var runtimeConfiguration = new RuntimeConfiguration
86+
{
87+
NamespaceUriBase = this.NamespaceBaseUri,
88+
NamespaceUriUniquePart = this.NamespaceUriUniquePart,
89+
DeleteManifestDirectoryIfPresent = this.DeleteManifestDirIfPresent,
90+
Verbosity = ValidateAndAssignVerbosity(),
91+
};
92+
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
93+
var result = System.Threading.Tasks.Task.Run(() => this.Generator.GenerateSbomAsync(
94+
rootPath: this.BuildDropPath,
95+
manifestDirPath: this.ManifestDirPath,
96+
metadata: sbomMetadata,
97+
componentPath: this.BuildComponentPath,
98+
runtimeConfiguration: runtimeConfiguration,
99+
specifications: ValidateAndAssignSpecifications(),
100+
externalDocumentReferenceListFile: this.ExternalDocumentListFile)).GetAwaiter().GetResult();
101+
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
102+
103+
return result.IsSuccessful;
104+
}
105+
catch (Exception e)
106+
{
107+
Log.LogError($"SBOM generation failed: {e.Message}");
108+
return false;
109+
}
110+
}
111+
112+
/// <summary>
113+
/// Check for ManifestInfo and create an SbomSpecification accordingly.
114+
/// </summary>
115+
/// <returns>A list of the parsed manifest info. Null if the manifest info is null or empty.</returns>
116+
private IList<SbomSpecification> ValidateAndAssignSpecifications()
117+
{
118+
if (!string.IsNullOrWhiteSpace(this.ManifestInfo))
119+
{
120+
return [SbomSpecification.Parse(this.ManifestInfo)];
121+
}
122+
123+
return null;
124+
}
125+
}

0 commit comments

Comments
 (0)