Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using Microsoft.ComponentDetection.Contracts.TypedComponent;
using Microsoft.Extensions.Logging;

public class DotNetComponentDetector : FileComponentDetector, IExperimentalDetector
public class DotNetComponentDetector : FileComponentDetector
{
private const string GlobalJsonFileName = "global.json";
private readonly ICommandLineInvocationService commandLineInvocationService;
Expand Down Expand Up @@ -138,9 +138,12 @@
{
var lockFile = this.lockFileFormat.Read(processRequest.ComponentStream.Stream, processRequest.ComponentStream.Location);

if (lockFile.PackageSpec is null)
if (lockFile.PackageSpec is null || lockFile.PackageSpec.RestoreMetadata is null)
{
this.Logger.LogWarning("Lock file {LockFilePath} does not contain a PackageSpec.", processRequest.ComponentStream.Location);
// The lock file is not valid, or does not contain a PackageSpec.
// This could be due to the lock file being generated by a different version of the SDK.
// We should not fail the detector, but we should log a warning.
this.Logger.LogWarning("Lock file {LockFilePath} does not contain project information.", processRequest.ComponentStream.Location);

Check warning on line 146 in src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs

View check run for this annotation

Codecov / codecov/patch

src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs#L146

Added line #L146 was not covered by tests
return;
}

Expand Down Expand Up @@ -181,7 +184,7 @@
var targetType = this.GetProjectType(projectOutputPath, projectName, cancellationToken);

var componentReporter = this.ComponentRecorder.CreateSingleFileComponentRecorder(projectPath);
foreach (var target in lockFile.Targets)
foreach (var target in lockFile.Targets ?? [])
{
var targetFramework = target.TargetFramework?.GetShortFolderName();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public static IServiceCollection AddComponentDetection(this IServiceCollection s
services.AddSingleton<IExperimentConfiguration, SimplePipExperiment>();
services.AddSingleton<IExperimentConfiguration, RustCliDetectorExperiment>();
services.AddSingleton<IExperimentConfiguration, Go117DetectorExperiment>();
services.AddSingleton<IExperimentConfiguration, DotNetDetectorExperiment>();

// Detectors
// CocoaPods
Expand Down
Loading