sbom-tool
sbom-tool copied to clipboard
SBOM Task Outputs Directly to Console Instead of Using MSBuild Logging APIs
When using the SBOM task in an MSBuild project, the task outputs messages directly to the console rather than utilizing MSBuild's Logging APIs. This behavior results in cluttered and unstructured console output, which is not consistent with standard MSBuild practices. Proper logging through MSBuild's APIs would allow for better categorization and filtering of messages.
Steps to Reproduce:
- Create a .NET project and include the SBOM task.
- Run the command
dotnet pack -blto build the project with a binary log. - Observe the console output during the build process.
Expected behavior:
Sbom task should output messages through MSBuild logging APIs & categorized appropriately.
We can utilize TaskLoggingHelper:
public class SbomTask : Microsoft.Build.Utilities.Task
{
public override bool Execute()
{
// Example of logging an informational message
Log.LogMessage(MessageImportance.High, "Finding components...");
// Example of logging a warning
Log.LogWarning("No instructions received to scan docker images.");
// Example of logging an error
Log.LogError("An error occurred during SBOM generation.");
// Rest of the task implementation
return !Log.HasLoggedErrors;
}
}