Skip to content

Commit 81e93c7

Browse files
ericstjgrvillic
andauthored
Promote DotNet detector out of experiment (#1388)
* Fix a coup[e potential NullRefs in dotnet detector * Promote DotNet detector --------- Co-authored-by: Greg Villicana <[email protected]>
1 parent bf16661 commit 81e93c7

File tree

3 files changed

+7
-27
lines changed

3 files changed

+7
-27
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Microsoft.ComponentDetection.Detectors.DotNet;
1717
using Microsoft.ComponentDetection.Contracts.TypedComponent;
1818
using Microsoft.Extensions.Logging;
1919

20-
public class DotNetComponentDetector : FileComponentDetector, IExperimentalDetector
20+
public class DotNetComponentDetector : FileComponentDetector
2121
{
2222
private const string GlobalJsonFileName = "global.json";
2323
private readonly ICommandLineInvocationService commandLineInvocationService;
@@ -138,9 +138,12 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID
138138
{
139139
var lockFile = this.lockFileFormat.Read(processRequest.ComponentStream.Stream, processRequest.ComponentStream.Location);
140140

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

@@ -181,7 +184,7 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID
181184
var targetType = this.GetProjectType(projectOutputPath, projectName, cancellationToken);
182185

183186
var componentReporter = this.ComponentRecorder.CreateSingleFileComponentRecorder(projectPath);
184-
foreach (var target in lockFile.Targets)
187+
foreach (var target in lockFile.Targets ?? [])
185188
{
186189
var targetFramework = target.TargetFramework?.GetShortFolderName();
187190

src/Microsoft.ComponentDetection.Orchestrator/Experiments/DotNetDetectorExperiment.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public static IServiceCollection AddComponentDetection(this IServiceCollection s
6666
services.AddSingleton<IExperimentConfiguration, SimplePipExperiment>();
6767
services.AddSingleton<IExperimentConfiguration, RustCliDetectorExperiment>();
6868
services.AddSingleton<IExperimentConfiguration, Go117DetectorExperiment>();
69-
services.AddSingleton<IExperimentConfiguration, DotNetDetectorExperiment>();
7069

7170
// Detectors
7271
// CocoaPods

0 commit comments

Comments
 (0)