Coder Social home page Coder Social logo

cyclonedx / cyclonedx-dotnet Goto Github PK

View Code? Open in Web Editor NEW
169.0 13.0 79.0 2.67 MB

Creates CycloneDX Software Bill of Materials (SBOM) from .NET Projects

Home Page: https://cyclonedx.org/

License: Apache License 2.0

C# 99.72% Shell 0.05% Dockerfile 0.22%
bom spdx dotnet dotnet-core bill-of-materials software-bill-of-materials package-url purl sbom cyclonedx

cyclonedx-dotnet's Introduction

Build Status Docker Image License NuGet Version Nuget Website Slack Invite Group Discussion Twitter

CycloneDX module for .NET

The CycloneDX module for .NET creates a valid CycloneDX bill-of-material document containing an aggregate of all project dependencies. CycloneDX is a lightweight BOM specification that is easily created, human readable, and simple to parse.

This module runs on

  • .NET 6.0
  • .NET 7.0
  • .NET 8.0

This module no longer runs on

Usage

CycloneDX for .NET is distributed via NuGet and Docker Hub.

Installing via NuGet

dotnet tool install --global CycloneDX

If you already have a previous version of CycloneDX installed, you can upgrade to the latest version using the following command:

dotnet tool update --global CycloneDX

Execution via DotNet

dotnet CycloneDX <path> -o <OUTPUT_DIRECTORY>

Execution via Docker

docker run cyclonedx/cyclonedx-dotnet [OPTIONS] <path>

Options

Usage:
  CycloneDX <path> [options]

Arguments:
  <path>  The path to a .sln, .csproj, .fsproj, .vbproj, or packages.config file or the path to a directory which will be recursively analyzed for packages.config files.

Options:
  -tfm, --framework <framework>                                                The target framework to use. If not defined, all will be aggregated.
  -rt, --runtime <runtime>                                                     The runtime to use. If not defined, all will be aggregated.
  -o, --output <output>                                                        The directory to write the BOM
  -fn, --filename <filename>                                                   Optionally provide a filename for the BOM (default: bom.xml or bom.json)
  -j, --json                                                                   Produce a JSON BOM instead of XML
  -ed, --exclude-dev                                                           Exclude development dependencies from the BOM (see https://github.com/NuGet/Home/wiki/DevelopmentDependency-support-for-PackageReference)
  -t, --exclude-test-projects                                                  Exclude test projects from the BOM
  -u, --url <url>                                                              Alternative NuGet repository URL to https://<yoururl>/nuget/<yourrepository>/v3/index.json
  -us, --baseUrlUsername <baseUrlUsername>                                     Alternative NuGet repository username
  -usp, --baseUrlUserPassword <baseUrlUserPassword>                            Alternative NuGet repository username password/apikey
  -uspct, --isBaseUrlPasswordClearText                                         Alternative NuGet repository password is cleartext
  -rs, --recursive                                                             To be used with a single project file, it will recursively scan project references of the supplied project file
  -ns, --no-serial-number                                                      Optionally omit the serial number from the resulting BOM
  -gu, --github-username <github-username>                                     Optionally provide a GitHub username for license resolution. If set you also need to provide a GitHub personal access token
  -gt, --github-token <github-token>                                           Optionally provide a GitHub personal access token for license resolution. If set you also need to provide a GitHub username
  -gbt, --github-bearer-token <github-bearer-token>                            Optionally provide a GitHub bearer token for license resolution. This is useful in GitHub actions
  -egl, --enable-github-licenses                                               Enables GitHub license resolution
  -dpr, --disable-package-restore                                              Optionally disable package restore
  -dhc, --disable-hash-computation                                             Optionally disable hash computation for packages
  -dct, --dotnet-command-timeout <dotnet-command-timeout>                      dotnet command timeout in milliseconds (primarily used for long dotnet restore operations) [default: 300000]
  -biop, --base-intermediate-output-path <base-intermediate-output-path>       Optionally provide a folder for customized build environment. Required if folder 'obj' is relocated.
  -imp, --import-metadata-path <import-metadata-path>                          Optionally provide a metadata template which has project specific details.
  -ipr, --include-project-references                                           Include project references as components (can only be used with project files).
  -sn, --set-name <set-name>                                                   Override the autogenerated BOM metadata component name.
  -sv, --set-version <set-version>                                             Override the default BOM metadata component version (defaults to 0.0.0).
  -st, --set-type   <Application|Container|Data|Device|Device_Driver|          Override the default BOM metadata component type (defaults to application). [default: Application]
                     File|Firmware|Framework|Library|
                     Machine_Learning_Model|Null|Operating_System|Platform>                                                                
  --version                                                                    Show version information
  -?, -h, --help                                                               Show help and usage information

Examples

To run the CycloneDX tool you need to specify a solution or project file. In case you pass a solution, the tool will aggregate all the projects.

The following will create a BOM from a solution and all projects defined within:

dotnet CycloneDX YourSolution.sln -o /output/path

The following will recursively scan the directory structure for packages.config and create a BOM:

dotnet CycloneDX /path/to/project -o /output/path

The following will recursively scan the project references of the supplied project file, and create a BOM of all package references from all included projects:

dotnet CycloneDX /path/to/project/MyProject.csproj -o /output/path -rs

Project metadata template example

<?xml version="1.0" encoding="utf-8"?>
<bom xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" serialNumber="urn:uuid:087d0712-f591-4995-ba76-03f1c5c48884" version="1" xmlns="http://cyclonedx.org/schema/bom/1.2">
  <metadata>
    <component type="application" bom-ref="pkg:nuget/[email protected]">
      <name>CycloneDX</name>
      <version>1.3.0</version>
      <description>
        <![CDATA[The [CycloneDX module](https://github.com/CycloneDX/cyclonedx-dotnet) for .NET creates a valid CycloneDX bill-of-material document containing an aggregate of all project dependencies. CycloneDX is a lightweight BOM specification that is easily created, human readable, and simple to parse.]]>
      </description>
      <licenses>
        <license>
          <name>Apache License 2.0</name>
          <id>Apache-2.0</id>
        </license>
      </licenses>
      <purl>pkg:nuget/[email protected]</purl>
    </component>
  </metadata>
</bom>

Update the data and import it within a build pipeline e.g. create the file using a script and add also dynamic data (version, timestamp, ...)

GitHub License Resolution

SPDX license IDs can be resolved for packages that reference a supported license file in a GitHub repository.

The GitHub license API has an unauthenticated call limit of 60 calls per hour. To ensure consistent output if a rate limit is exceeded BOM generation will fail. If you start hitting rate limits you will need to generate a personal access token and provide this, and your username, when running CycloneDX.

To generate a token go to Personal access tokens under Settings / Developer setings. From there select the option to Generate new token. No special token permissions are required.

Due to current limitations in the GitHub API licenses will only be resolved for master branch license references.

License

Permission to modify and redistribute is granted under the terms of the Apache 2.0 license. See the LICENSE file for the full license.

Contributing

Pull requests are welcome. But please read the CycloneDX contributing guidelines first.

To build and test the solution locally you should have .NET 6.0 or .NET 7.0 installed. Standard commands like dotnet build and dotnet test work.

Alternatively, you can use VS Code and the included devcontainer configuration to work in a pre-configured docker image. (You will also need the "Remote - Containers" extension and Docker)

It is generally expected that pull requests will include relevant tests. Tests are automatically run on Windows, MacOS and Linux for every pull request. And build warnings will break the build.

If you are having trouble debugging a test that is failing for a platform you don't have access to please us know.

Thanks to Gitpod there is a really easy way of creating a ready to go development environment with VS Code. You can open a Gitpod hosted development environment in your browser.

Open in Gitpod

cyclonedx-dotnet's People

Contributors

aristotelos avatar bertk avatar blythmeister avatar brianvu-dysi avatar coderpatros avatar davideicardi avatar dependabot-preview[bot] avatar dependabot[bot] avatar dhivarson avatar falco20019 avatar hanstdam avatar jankrivanek avatar karolswdev avatar killi199 avatar logicaloud avatar mangofloat avatar morganthrapp avatar mtsfoni avatar nejch avatar nil4 avatar patspaeth avatar rocallaghan-deluxe avatar rodneyrichardson avatar scorgatelli-docutech avatar sescandell avatar shawner18 avatar st-apps avatar stas-kachurovskyi avatar stevespringett avatar verzada avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cyclonedx-dotnet's Issues

Empty BOM file is created for project using Arcade tooling

Hi,
I use Microsoft dotnet Arcade tools for csharp projects and CyclonDX does always create a empty BOM file whenever the Arcade extensions are activated. After removing the Arcade tooling (global.json, Directory.Build.props, Directory.Build.targets) a complete BOM is created.

How to reproduce: clone Arcade repository and run CycloneDX tool: dotnet CycloneDX Arcade.sln --out lincenseDX

The generated BOM.xml file:

<?xml version="1.0" encoding="utf-8"?>
<bom version="1" serialNumber="urn:uuid:c4bc047c-9409-4f19-aa68-b7aad0a195f5" xmlns="http://cyclonedx.org/schema/bom/1.1">
  <components />
</bom>

Exception when trying to restore packages is not exploitable

When trying to restore package for generation the SBOM, I have an exception but it is not useful:

» Analyzing: mySolution.csproj
  Attempting to restore packages
Dotnet restore failed:

Unhandled exception. CycloneDX.Services.DotnetRestoreException: Exception of type 'CycloneDX.Services.DotnetRestoreException' was thrown.
   at CycloneDX.Services.ProjectFileService.GetProjectNugetPackagesAsync(String projectFilePath) in /Users/steve/Development/CycloneDX/cyclonedx-dotnet/CycloneDX/Services/ProjectFileService.cs:line 92
   at CycloneDX.Services.SolutionFileService.GetSolutionNugetPackages(String solutionFilePath) in /Users/steve/Development/CycloneDX/cyclonedx-dotnet/CycloneDX/Services/SolutionFileService.cs:line 110
   at CycloneDX.Program.OnExecuteAsync() in /Users/steve/Development/CycloneDX/cyclonedx-dotnet/CycloneDX/Program.cs:line 128
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.InvokeAsync(MethodInfo method, Object instance, Object[] arguments)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync[TApp](CommandLineContext context, CancellationToken cancellationToken)
   at CycloneDX.Program.Main(String[] args) in /Users/steve/Development/CycloneDX/cyclonedx-dotnet/CycloneDX/Program.cs:line 62
   at CycloneDX.Program.<Main>(String[] args)

This is probably an issue with a local package, but the exception is not explicit.

No scan of components imported from generated sbom in Dependency-Track

Hi,
I imported my project in Dependency-Track from a generated sbom generated from my sln project.
The project and its components are well imported but they are not scanned.
For example the component Microsoft.AspNetCore.App version 2.2.0 is associated with CVE-2019-0564 but the vulnerability is not detected.
Does anyone have the same issue ?
I attached the sbom file and the Dependency-Track component screen.

Regards.

bom.zip
gitub_issue

Builds should be deterministic

This probably depends on #174 being resolved first.

This would enable users of this implementation to verify what has been published to nuget matches the relevant commit tag.

We should match the defacto standard for lowercase command name and parameter options

A defacto standard is to have lowercase dotnet command names and parameters. I'm proposing to add lowercase equivalents for current parameters while still supporting existing parameters.

This would include updating all documentation to reference the lowercase equivalents. And only add new parameters in lowercase.

There probably isn't any real maintenance overhead in keeping existing uppercase options. So no plans to deprecate them anytime soon.

BOM creation fails when used latest dotnet-CycloneDX (0.11.0)

Hi Steve,

When I am trying to use latest dotnet-CycloneDX (0.11.0) version for creating BOM file I am getting following message, so I am using dotnet-CycloneDX (0.9.0) is using:

¯ Analyzing: C:\Users\admin\file.csproj
  Getting project references
  No project references found
  1 project(s) found

My file.csproj contains following contents:

<Project>
  <ItemGroup>
    <!--Set Third party nuget versions-->	
    <PackageReference Include="AngleSharp" Version="0.9.4" />
	<PackageReference Include="Apache.NMS.ActiveMQ" Version="1.7.2" />
    <PackageReference Include="Aspose.BarCode" Version="19.4.0" />
    <PackageReference Include="Aspose.Cells" Version="19.8.0" />
    <PackageReference Include="Aspose.Pdf" Version="19.8.0" />
    <PackageReference Include="Aspose.Words" Version="20.1.0" />
  </ItemGroup>
</Project>

Incorrect Version getting added in bom.xml

Hi Team,

I am using "dotnet-CycloneDX" package for creating bom.xml from .sln file. But as per my observation it is adding incorrect version in bom.xml. For example the .csproj file contains following entry:

<PackageReference Include="WebGrease" version="1.6.0" />

In above it is clear that the version of WebGrease is 1.6.0 but if we check the bom.xml it shows version 1.5.2 as follows:

    <component type="library">
      <name>WebGrease</name>
      <version>1.5.2</version>
      <description><![CDATA[Web Grease is a suite of tools for optimizing javascript, css files and images.]]></description>
      <licenses>
        <license>
          <url>http://www.microsoft.com/web/webpi/eula/msn_webgrease_eula.htm</url>
        </license>
      </licenses>
      <purl>pkg:nuget/[email protected]</purl>
    </component>

Also I have observed that it includes version of library which is not present either in .csproj or packages.config file.

For example:
packages.config file contains:
<package id="WebGrease" version="1.6.0" targetFramework="net45" />

but bom.xml file contains 2 entries for WebGrease one 1.6.0 and other with version 1.5.2 as shown below:

    <component type="library">
      <name>WebGrease</name>
      <version>1.5.2</version>
      <description><![CDATA[Web Grease is a suite of tools for optimizing javascript, css files and images.]]></description>
      <licenses>
        <license>
          <url>http://www.microsoft.com/web/webpi/eula/msn_webgrease_eula.htm</url>
        </license>
      </licenses>
      <purl>pkg:nuget/[email protected]</purl>
    </component>

    <component type="library">
      <name>WebGrease</name>
      <version>1.6.0</version>
      <description><![CDATA[Web Grease is a suite of tools for optimizing javascript, css files and images.]]></description>
      <licenses>
        <license>
          <url>http://www.microsoft.com/web/webpi/eula/aspnetcomponent_rtw_ENU.htm</url>
        </license>
      </licenses>
      <purl>pkg:nuget/[email protected]</purl>
      <externalReferences>
        <reference type="website">
          <url>http://webgrease.codeplex.com/</url>
        </reference>
      </externalReferences>
    </component>

Could you please take a look into it and let me know if I am missing something?

Support net5

Does somebody in this project and community is working on net5 compatibility? It's clear that it's not supported until now from project home page. But raising issue to get fast feedback was idea. Thanks for your feedback in advance

Support for "dll" references (non-nuget) projects in .NET based projects

Can we add support for including components that are added as "dll" references in .NET projects, in the generated CycloneDX BOM? I understand that the "dll" reference may not have all the information CycloneDX spec will require - but for teams who need to aggregate all their components to BOM - this will be a good feature. This feature could be added as optional, managed by a optional parameter to the tool.

.net full framework solution file support

It would be great if this tool could recognise full framework solution files and switch to scanning for packages.config files.

My use case is that I want to run this against a lot of git repositories and it would be nice to use the same command regardless of the project.

It does add some complexity though. So understand if you don't want to go there. But I'd be happy to have a go at implementing it.

Issues retrieving package info for Private Azure DevOps Nuget feed since 0.9.1

Hello,

Since the 0.9.1 update we have been having issues retrieving nuget package information that is hosted in our private Nuget Feed. I've tried specifying the url, only to receive a 401 unauthorized error. Previously we we would simply not specify the url. I'm assuming we would need to pass an authentication token, but I don't see a way for us to do this currently.

image

Thanks,
Edouard

Processing solution file doesn't include secondary project references

If a project file references a project that isn't included in the solution file the corresponding packages will not be included in the BOM.

i.e. Solution File references just project1.csproj, and project1.csproj references project2.csproj
Then project2.csproj packages will not be included in BOM.

Offending method is

/*
* Analyzes all projects in a Solution.
*/
async Task<int> AnalyzeSolutionAsync(string solutionFile) {
if (!File.Exists(solutionFile)) {
Console.Error.WriteLine($"Solution file \"{solutionFile}\" does not exist");
return 1;
}
Console.WriteLine();
Console.WriteLine($"» Solution: {solutionFile}");
Console.WriteLine(" Getting projects".PadRight(64));
var solutionFolder = Path.GetDirectoryName(solutionFile);
var projects = new List<string>();
try {
using (var reader = File.OpenText(solutionFile)) {
string line;
while ((line = await reader.ReadLineAsync()) != null) {
if (!line.StartsWith("Project", StringComparison.OrdinalIgnoreCase)) {
continue;
}
var regex = new Regex("(.*) = \"(.*?)\", \"(.*?)\"");
var match = regex.Match(line);
if (match.Success) {
var relativeProjectPath = match.Groups[3].Value.Replace('\\', Path.DirectorySeparatorChar);
var projectFile = Path.GetFullPath(Path.Combine(solutionFolder, relativeProjectPath));
if (isSupportedProjectType(projectFile) && File.Exists(projectFile)) {
projects.Add(projectFile);
}
}
}
}
} catch (Exception ex) {
Console.Error.WriteLine($" An unhandled exception occurred while getting the projects: {ex.Message}");
return 1;
}
if (!projects.Any()) {
Console.Error.WriteLine(" No projects found".PadRight(64));
return 0;
}
Console.WriteLine($" {projects.Count} project(s) found".PadRight(64));
foreach (var project in projects) {
Console.WriteLine();
var ret = await AnalyzeProjectAsync(project);
if (ret != 0) {
return ret;
}
}
return 0;
}

Will be addressed by #20

Add support for "dotnet-retire"

I've just found RetireNet. This tools produces massive more information and also finds some vulnerabilities.

  • It scans all transitive dependencies,
  • It includes .NET Framework / .NET Core version aswell
    • I think this is very important, because MSFT mostly publish vulnerabilities for a specific .netcore version

Maybe you can include dotnet-retire and create a bom.xml out of scan results from dotnet-retire. Or add parameter to add additional input from output

Regarding CycloneDX Spec, it's also possibile to add vulnerabilities to the bom.xml

What do you think?

Without arguments, ArgumentNullException

Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: path
at System.IO.Path.GetFullPath(String path)
at CycloneDX.Program.OnExecute() in /Users/steve/Development/CycloneDX/cyclonedx-dotnet/CycloneDX/Program.cs:line 51
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.InvokeAsync(MethodInfo method, Object instance, Object[] arguments) in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 77
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context) in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 62
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<b__0>d.MoveNext() in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 25
--- End of stack trace from previous location where exception was thrown ---
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass126_0.b__0() in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.cs:line 505
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](CommandLineContext context) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 31
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](IConsole console, String[] args) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 97
at CycloneDX.Program.Main(String[] args) in /Users/steve/Development/CycloneDX/cyclonedx-dotnet/CycloneDX/Program.cs:line 45

No automated tests

No automated tests makes vetting pull requests even more time consuming.

I noticed your comment @stevespringett on another issue that you aren't a .net developer. I'm opening this issue to find out if you want a .net developer to jump in and work on this.

It would be a bit of effort to implement, and review. So please let me know if you are interested. Although I do have a bit of free time over the next couple of days so I'll probably make a start on it anyway.

Internal project references should be excluded from the BOM

As pointed out in the #181 thread, internal project references are included in the BOM. I think these should be excluded.

The one scenario I can think of for including them is if the project reference is to a project that is also a nuget package. However, even this is problematic. The reference might not match the relevant nuget package. In particular because of how package versions are managed by some build/release projects.

Exception thrown for projects with no information under SDK 3.1

Dear cyclonedx-dotnet team,

I discovered an issue with this product.

When cyclonedx-dotnet attempts to retreive info for a local project that is listed as a dependency for another project but contains very little info about itself (such as the below) it blows up.

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>netstandard2.1</TargetFramework>
    </PropertyGroup>

</Project>

It looks like it is a bug in the framework you use for reading NuSpec details.

I created a sample repo for your convenience to easily reproduce this issue:

https://github.com/karolswdev/cyclonedx-0-9-1-bug

I checked other issues but they were closed and opened quite a while back.

Local nuget cache for bulk BOM generation

We have a lot of existing projects. So we don't have to go back and add bom generation to all our existing build pipelines we have a script that generates them in bulk.

I suspect this would be significantly faster by keeping a local, on disk, cache of already resolved nuget packages.

If implemented I think this should be opt in.

Any thoughts @stevespringett ?

Include support for package.json files also

It would be good to be able to support multiple package providers in the solution.
For example, a web application solution may consume packages from both NuGet and NPM and thus the SBOM should aggregate both sets of references.

.NET core 3.x support

Hi All.

Disclaimer: I tried looking through the Wiki and your README file but could not find the answer.

I am tasked to create BOM during CI/CD pipelines using GitHub Actions.

I discovered your wonderful plugin and decided to give it a shot. We have recently moved all of our projects from .NET core 2.X to 3.1. It seems that your tool does not support 3.1 project, is that a correct assumption?

The error I am getting is

Run ./dotnet-CycloneDX ExampleNetCore/ExampleNetCore.csproj -o bom/
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
  - The following frameworks were found:
      3.1.0 at [/opt/hostedtoolcache/dncs/3.1.100/x64/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.1.0&arch=x64&rid=ubuntu.18.04-x64
##[error]Process completed with exit code 150.

Any clarity on your strategy and/or instructions how to contribute to getting this feature moving would be great. Thanks

Karol

.NET 4 support

Hi I was wondering if CycloneDX-dotnet supports scanning the classic .NET 4 framework instead of .NET CORE. I'm able to run it on the project *.sln but I'm not getting any dependencies as a result.
Any ideas?

A Docker container image would make it easier to deal with different runtime versions

Pretty much what the title says. For situations where you aren't running a current LTS runtime or don't want to worry about what runtime versions are available.

Dockerfile is ready to go here...
https://github.com/coderpatros/cyclonedx-dotnet/blob/docker/Dockerfile

But wanted to gauge your interest first @stevespringett. If you'd prefer not to have another thing to worry about I can just keep it as an unofficial image.

You can find it here (assuming the dockerhub build has finished, they can be slow)...
https://hub.docker.com/r/coderpatros/cyclonedx-dotnet

Make github license lookup optional

My organisation only produces software for in-house usage so we are not liable for license infringement. Furthermore, the github lookup is bothersome because our build servers are not supposed to have a direct Internet access, we must edit our firewall rules because of that. Is it possible to make this lookup optional?

Discuss inviting @coderpatros to team

@coderpatros With all of your contributions (and two more PR's possibly ready for merge?), I'm wondering if it would make sense to invite you to the team, which would provide more direct access to the repos, ability to merge PRs, etc.

Let me know if this is something you're interested in. If not, no worries. We can continue collaborating the way we have been. Your call.

Exclude DevelopmentDependency from bom.xml

Later .csproj files supports package references with are just used in development scope.

They usually looks like:

<PackageReference Include="Foo" Version="1.0.0">
   <PrivateAssets>all</PrivateAssets>
   <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

This could be Roslyn.Analyzers, SourceLink packages, ... which will never go to production.

see DevelopmentDependency

I think it would be good to exclude such dependencies.

Hardcoded timeout limit for dotnet command leads to problems with debugging

Steps to reproduce:

  1. See that sometimes cyclonedx-dotnet returns Dotnet restore failed: and so can't make result bom file
  2. In same case when run it pair with dotnet restore command everything is ok

Current result:
dotnet restore is called inside cyclonedx-dotnet in DotnetUtilsService.cs

        public DotnetUtilsResult Restore(string path)
        {
            var arguments = "restore";
            if (!string.IsNullOrEmpty(path)) arguments = $"{arguments} \"{path}\"";

            var commandResult = _dotnetCommandService.Run(arguments);

            if (commandResult.Success)
            {
                return new DotnetUtilsResult();
            }
            else
            {
                return new DotnetUtilsResult
                {
                    // dotnet restore only outputs to std out, not std err
                    ErrorMessage = commandResult.StdOut
                };
            }
        }

If look on dotnetCommandService.Run

public DotnetCommandResult Run(string workingDirectory, string arguments)
        {
            var psi = new ProcessStartInfo(DotNetExe.FullPathOrDefault(), arguments)
            {
                CreateNoWindow = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                UseShellExecute = false,
                WorkingDirectory = workingDirectory
            };
            
            using (var p = Process.Start(psi))
            {
                var exitCode = 0;
                // ...
                var processExited = p.WaitForExit(60000);
                if (processExited)
                {
                    exitCode = p.ExitCode;
                }
                else
                {
                    p.Kill();
                    exitCode = -1;
                }
                // ...
                return result;
            }

Here we see hard-limit for 60 sec to call dotnet restore. It could be not enough in some cases, e.g. when you need to download 400+ heavyweight dependencies

Expected result:

  1. Add option for cyclonedx-dotnet to change this time limit
  2. Add error message to output about the limit passing event

Getting XML Exception while executing dotnet cyclonedx

Version used: 1.3.0

Exception:
Unhandled exception. System.Xml.XmlException: There is no Unicode byte order mar
k. Cannot switch to Unicode.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.CheckEncoding(String newEncodingName)
at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl)
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at NuGet.Packaging.Core.NuspecCoreReaderBase.LoadXml(Stream stream, Boolean l
eaveStreamOpen)
at NuGet.Packaging.Core.NuspecCoreReaderBase..ctor(Stream stream, Boolean lea
veStreamOpen)
at NuGet.Packaging.NuspecReader..ctor(Stream stream, IFrameworkNameProvider f
rameworkProvider, Boolean leaveStreamOpen)
at NuGet.Packaging.NuspecReader..ctor(Stream stream)
at CycloneDX.Services.NugetService.GetComponentAsync(String name, String vers
ion, String scope) in /home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/Cyclon
eDX.Core/Services/NugetService.cs:line 110
at CycloneDX.Services.NugetService.GetComponentAsync(NugetPackage package) in
/home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/CycloneDX.Core/Services/Nug
etService.cs:line 219
at CycloneDX.Program.OnExecuteAsync() in /home/runner/work/cyclonedx-dotnet/c
yclonedx-dotnet/CycloneDX/Program.cs:line 211
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.I
nvokeAsync(MethodInfo method, Object instance, Object[] arguments)
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.O
nExecute(ConventionContext context, CancellationToken cancellationToken)
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<

c__DisplayClass0_0.<b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(S
tring[] args, CancellationToken cancellationToken)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync[T
App](CommandLineContext context, CancellationToken cancellationToken)
at CycloneDX.Program.Main(String[] args) in /home/runner/work/cyclonedx-dotne
t/cyclonedx-dotnet/CycloneDX/Program.cs:line 90
at CycloneDX.Program.

(String[] args)

Build server error

Running the latest cyclonedx-dotnet (0.3.1) on my TFS build server.
Notice the /Users/steve/... path?
Did a development version get installed? If so, how can I rectify this?

2019-01-23T15:30:34.4838674Z » Analyzing: F:\Agents\Agent01\_work\4\s\Audio\APITestHarnes\packages.config
2019-01-23T15:30:34.4838674Z   Getting packages                                              
2019-01-23T15:30:40.6871154Z ##[error]Unhandled Exception: System.IO.IOException: The handle is invalid
2019-01-23T15:30:40.6871154Z ##[error]   at System.ConsolePal.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
2019-01-23T15:30:40.6871154Z ##[error]   at CycloneDX.Program.AnalyzeProjectAsync(String projectFile) in /Users/steve/Development/CycloneDX/cyclonedx-dotnet/CycloneDX/Program.cs:line 177
2019-01-23T15:30:40.6871154Z ##[error]   at CycloneDX.Program.AnalyzeDirectoryAsync(String projectPath) in /Users/steve/Development/CycloneDX/cyclonedx-dotnet/CycloneDX/Program.cs:line 157
2019-01-23T15:30:40.6871154Z ##[error]   at CycloneDX.Program.OnExecute() in /Users/steve/Development/CycloneDX/cyclonedx-dotnet/CycloneDX/Program.cs:line 79
2019-01-23T15:30:40.6871154Z ##[error]   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.InvokeAsync(MethodInfo method, Object instance, Object[] arguments) in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 77
2019-01-23T15:30:40.6871154Z ##[error]   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context) in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 62
2019-01-23T15:30:40.6871154Z ##[error]   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext() in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 25
2019-01-23T15:30:40.6871154Z ##[error]--- End of stack trace from previous location where exception was thrown ---
2019-01-23T15:30:40.6871154Z ##[error]   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass126_0.<OnExecute>b__0() in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.cs:line 505
2019-01-23T15:30:40.6871154Z ##[error]   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](CommandLineContext context) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 31
2019-01-23T15:30:40.7027422Z ##[error]   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](IConsole console, String[] args) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 97
2019-01-23T15:30:40.7027422Z ##[error]   at CycloneDX.Program.Main(String[] args) in /Users/steve/Development/CycloneDX/cyclonedx-dotnet/CycloneDX/Program.cs:line 45```

Empty BOM file generated when using it on a .NET Core 3.1 project

When i try to run cyclonedx on my project i get a empty bom file.

Cyclonedx-dotnet version:

Package Id      Version      Commands
---------------------------------------------
cyclonedx       1.0.2        dotnet-CycloneDX

the file contents are as follows:

<?xml version="1.0" encoding="utf-8"?>
<bom version="1" serialNumber="urn:uuid:8acd057e-4e88-48cf-8ce7-d0f5a6120c73" xmlns="http://cyclonedx.org/schema/bom/1.1">
  <components />
</bom>

Here is the output of the command:

Found the following local nuget package cache locations:
    <redacted-path>/FeaturePeer.AlertSettings/packages
» Solution: <redacted-path>/FeaturePeer.AlertSettings/AlertSettings.sln
  Getting projects
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.PeerApplication/AlertSettings.PeerApplication.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Peer/AlertSettings.Peer.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services.Abstractions/AlertSettings.Services.Abstractions.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services/AlertSettings.Services.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services.Abstractions/AlertSettings.Services.Abstractions.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services/AlertSettings.Services.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Peer/AlertSettings.Peer.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services.Abstractions/AlertSettings.Services.Abstractions.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services/AlertSettings.Services.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services/AlertSettings.Services.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services.Abstractions/AlertSettings.Services.Abstractions.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services.Abstractions/AlertSettings.Services.Abstractions.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/Tests/Module.Tests/Module.Tests.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.PeerApplication/AlertSettings.PeerApplication.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Peer/AlertSettings.Peer.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services.Abstractions/AlertSettings.Services.Abstractions.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services/AlertSettings.Services.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Peer/AlertSettings.Peer.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services.Abstractions/AlertSettings.Services.Abstractions.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services/AlertSettings.Services.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services.Abstractions/AlertSettings.Services.Abstractions.csproj
  Getting project references
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services/AlertSettings.Services.csproj
  Getting project references
  5 project(s) found
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.PeerApplication/AlertSettings.PeerApplication.csproj
  Attempting to restore packages
  No packages found
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Peer/AlertSettings.Peer.csproj
  Attempting to restore packages
  No packages found
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services/AlertSettings.Services.csproj
  Attempting to restore packages
  No packages found
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/src/AlertSettings.Services.Abstractions/AlertSettings.Services.Abstractions.csproj
  Attempting to restore packages
  No packages found
» Analyzing: <redacted-path>/FeaturePeer.AlertSettings/Tests/Module.Tests/Module.Tests.csproj
  Attempting to restore packages
  No packages found
Creating CycloneDX BOM
Writing to: <redacted-path>/FeaturePeer.AlertSettings/target/bom.xml

Unhandled exception when nuget.org is not available.

I am trying to run CycloneDX on a build server that does not have internet access. My packages are hosted in a package source on the LAN that the build server does have access to. CycloneDX gets an error like this while trying to retrieve information for one of the libraries in my solution. Since its my own library, it does not have a NuGet package. CycloneDX can't find a local package file, so it tries to connect to nuget.org which it cannot. I think that CycloneDX should be able to run without access to the internet.

     Retrieving System.Threading.Tasks.Extensions 4.0.0
     Retrieving System.Threading.Thread 4.0.0
     Retrieving System.Threading.ThreadPool 4.0.10
     Retrieving System.Xml.ReaderWriter 4.0.11
     Retrieving System.Xml.XDocument 4.0.11
     Retrieving System.Xml.XmlDocument 4.0.1
     Retrieving System.Xml.XmlSerializer 4.0.11
     Retrieving System.Xml.XPath 4.0.1
     Retrieving System.Xml.XPath.XmlDocument 4.0.1
     Retrieving My.Library 1.0.0-176678
     
     Unhandled Exception: System.Net.Http.HttpRequestException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
        at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
        --- End of inner exception stack trace ---
        at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
        at System.Threading.Tasks.ValueTask`1.get_Result()
        at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        at System.Threading.Tasks.ValueTask`1.get_Result()
        at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
        at System.Threading.Tasks.ValueTask`1.get_Result()
        at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
        at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
        at CycloneDX.Extensions.HttpClientExtensions.GetXmlStreamAsync(HttpClient httpClient, String url) in /home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/CycloneDX.Core/Extensions/HttpClientExtensions.cs:line 37
        at CycloneDX.Services.NugetService.GetComponentAsync(String name, String version) in /home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/CycloneDX.Core/Services/NugetService.cs:line 107
        at CycloneDX.Services.NugetService.GetComponentAsync(NugetPackage package) in /home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/CycloneDX.Core/Services/NugetService.cs:line 209
        at CycloneDX.Program.OnExecuteAsync() in /home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/CycloneDX/Program.cs:line 179
        at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.InvokeAsync(MethodInfo method, Object instance, Object[] arguments)
        at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context, CancellationToken cancellationToken)
        at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext()
     --- End of stack trace from previous location where exception was thrown ---
        at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
        at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync[TApp](CommandLineContext context, CancellationToken cancellationToken)
        at CycloneDX.Program.Main(String[] args) in /home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/CycloneDX/Program.cs:line 69
        at CycloneDX.Program.<Main>(String[] args)

This is the part of the code that is making the network request that fails. I think it should either catch the network exception, or else give the user the option to remove nuget.org as a package source to avoid this request.

        if (nuspecFilename == null)
        {
            var url = _baseUrl + name + "/" + version + "/" + name + ".nuspec";
            using (var xmlStream = await _httpClient.GetXmlStreamAsync(url).ConfigureAwait(false))
            {
                if (xmlStream != null) nuspecReader = new NuspecReader(xmlStream);
            }
        }
        else
        {
            using (var xmlStream = _fileSystem.File.Open(nuspecFilename, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                nuspecReader = new NuspecReader(xmlStream);
            }
        }

non dotnet core projects

Does this support scanning of .net framework projects?
I'm unable to get this to work for my .net framework 4.5/4.6 solutions.

Specifying a directory should process all solution, project and packages files within

Some projects are made up of multiple system components. They may be separated at the project level or solution level within a repo. A repo might also contain a combination of legacy (older format) full framework projects and new .net core and standard projects.

It would make BOM generation simpler if specifying a directory processed all solution, project and packages files within.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.