Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NuGet Package Format and Surface Errors #619

Merged
merged 13 commits into from
Jul 30, 2024
50 changes: 35 additions & 15 deletions src/Microsoft.Sbom.Targets/Microsoft.Sbom.Targets.targets
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
<!--Set the SBOM CLI Tool path. This variable is only used in SbomCLIToolTask.cs-->
<SbomToolPath Condition=" '$(MSBuildRuntimeType)' == 'Full'">$(MSBuildThisFileDirectory)\..\tasks\$(GenerateSbom_TFM)\sbom-tool</SbomToolPath>
<ManifestFolderName>_manifest</ManifestFolderName>
<SbomSpecification>spdx_2.2</SbomSpecification>
</PropertyGroup>

<!-- Copy the SBOM files to each respective target framework folder within the .nupkg -->
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>
$(TargetsForTfmSpecificBuildOutput);CopySbomOutput
</TargetsForTfmSpecificBuildOutput>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.sha256</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<!--Based on the MSBuild runtime, GenerateSbom will either pull the GenerateSbomTask or SbomCLIToolTask logic-->
Expand Down Expand Up @@ -58,23 +67,34 @@
<Output TaskParameter="SbomPath" PropertyName="SbomPathResult" />
</GenerateSbom>
<Message Importance="High" Text="Task result: $(SbomPathResult)" />
</Target>

<!-- Specify the SBOM files to copy into the nuget package -->
<Target Name="CopySbomOutput" DependsOnTargets="GenerateSbomTarget">
<ItemGroup>
<!--Add manifest and SHA file from the GenerateSbomTask execution-->
<BuildOutputInPackage Condition=" '$(MSBuildRuntimeType)' == 'Core'"
Include="$(SbomPathResult)\$(SbomSpecification)\manifest.spdx.json"
TargetPath="_manifest/$(SbomSpecification)/manifest.spdx.json"/>
<BuildOutputInPackage Condition=" '$(MSBuildRuntimeType)' == 'Core'"
Include="$(SbomPathResult)\$(SbomSpecification)\manifest.spdx.json.sha256"
TargetPath="_manifest/$(SbomSpecification)/manifest.spdx.json.sha256"/>

<!-- Include the generated SBOM contents within the consumer's nuget package -->
<ItemGroup >
<Content Condition=" '$(MSBuildRuntimeType)' == 'Core'" Include="$(SbomPathResult)\**">
<Pack>true</Pack>
<PackagePath>_manifest</PackagePath>
</Content>
<!--Add manifest and SHA file from the SbomCLIToolTask execution from the default manifest path -->
<BuildOutputInPackage Condition=" '$(MSBuildRuntimeType)' == 'Full' And '$(SbomGenerationManifestDirPath)' == ''"
Include="$(SbomGenerationBuildDropPath)\$(ManifestFolderName)\$(SbomSpecification)\manifest.spdx.json"
vpatakottu marked this conversation as resolved.
Show resolved Hide resolved
TargetPath="_manifest/$(SbomSpecification)/manifest.spdx.json"/>
<BuildOutputInPackage Condition=" '$(MSBuildRuntimeType)' == 'Full' And '$(SbomGenerationManifestDirPath)' == ''"
Include="$(SbomGenerationBuildDropPath)\$(ManifestFolderName)\$(SbomSpecification)\manifest.spdx.json.sha256"
TargetPath="_manifest/$(SbomSpecification)/manifest.spdx.json.sha256"/>

<Content Condition=" '$(MSBuildRuntimeType)' == 'Full' And '$(SbomGenerationManifestDirPath)' == '' " Include="$(SbomGenerationBuildDropPath)\$(ManifestFolderName)\**">
<Pack>true</Pack>
<PackagePath>_manifest</PackagePath>
</Content>

<Content Condition=" '$(MSBuildRuntimeType)' == 'Full' And '$(SbomGenerationManifestDirPath)' != '' " Include="$(SbomGenerationManifestDirPath)\$(ManifestFolderName)\**">
<Pack>true</Pack>
<PackagePath>_manifest</PackagePath>
</Content>
<!--Add manifest and SHA file from the SbomCLIToolTask execution if a manifest directory was specified -->
<BuildOutputInPackage Condition=" '$(MSBuildRuntimeType)' == 'Full' And '$(SbomGenerationManifestDirPath)' != ''"
Include="$(SbomGenerationManifestDirPath)\$(ManifestFolderName)\$(SbomSpecification)\manifest.spdx.json"
TargetPath="_manifest/$(SbomSpecification)/manifest.spdx.json"/>
<BuildOutputInPackage Condition=" '$(MSBuildRuntimeType)' == 'Full' And '$(SbomGenerationManifestDirPath)' != ''"
Include="$(SbomGenerationManifestDirPath)\$(ManifestFolderName)\$(SbomSpecification)\manifest.spdx.json.sha256"
TargetPath="_manifest/$(SbomSpecification)/manifest.spdx.json.sha256"/>
</ItemGroup>
</Target>
</Project>
3 changes: 2 additions & 1 deletion src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Microsoft.Sbom.Targets;

using System.Diagnostics.Tracing;
using System.IO;
using Microsoft.Build.Utilities;

Expand Down Expand Up @@ -97,5 +96,7 @@ private void SetOutputImportance()
{
this.StandardOutputImportance = "Low";
}

this.LogStandardErrorAsError = true;
}
}