From cf60d1ada687aa7c7f6dd170da1a90e333a97cbf Mon Sep 17 00:00:00 2001 From: Topper154 Date: Mon, 21 Mar 2022 11:18:25 +0100 Subject: [PATCH] Add support for single project.assets.json file which can be use in projects build in NUKE Signed-off-by: Topper154 --- CycloneDX/Program.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/CycloneDX/Program.cs b/CycloneDX/Program.cs index 701137ee..6556ea4c 100644 --- a/CycloneDX/Program.cs +++ b/CycloneDX/Program.cs @@ -231,6 +231,11 @@ async Task OnExecuteAsync() { packages = await packagesFileService.GetNugetPackagesAsync(fullSolutionOrProjectFilePath).ConfigureAwait(false); topLevelComponent.Name = fileSystem.Path.GetDirectoryName(fullSolutionOrProjectFilePath); } + else if (Program.fileSystem.Path.GetFileName(SolutionOrProjectFile).ToLowerInvariant().Equals("project.assets.json", StringComparison.OrdinalIgnoreCase)) + { + packages = projectAssetsFileService.GetNugetPackages(fullSolutionOrProjectFilePath, false); + topLevelComponent.Name = fileSystem.Path.GetDirectoryName(fullSolutionOrProjectFilePath); + } else if (fileSystem.Directory.Exists(fullSolutionOrProjectFilePath)) { packages = await packagesFileService.RecursivelyGetNugetPackagesAsync(fullSolutionOrProjectFilePath).ConfigureAwait(false); @@ -281,13 +286,14 @@ async Task OnExecuteAsync() { }; if (package.Dependencies != null) { - foreach (var dep in package.Dependencies) + foreach (var (key, value) in package.Dependencies) { - transitiveDepencies.Add(bomRefLookup[(dep.Key.ToLower(CultureInfo.InvariantCulture), dep.Value.ToLower(CultureInfo.InvariantCulture))]); - packageDepencies.Dependencies.Add(new Dependency - { - Ref = bomRefLookup[(dep.Key.ToLower(CultureInfo.InvariantCulture), dep.Value.ToLower(CultureInfo.InvariantCulture))] - }); + var component = await nugetService + .GetComponentAsync(new NugetPackage { Name = key, Version = value }) + .ConfigureAwait(false); + + transitiveDepencies.Add(component.BomRef); + packageDepencies.Dependencies.Add(new Dependency { Ref = component.BomRef }); } } dependencies.Add(packageDepencies);