diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs index 1ba8827c9d29..6701f993ac6e 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/Analyser.cs @@ -360,5 +360,22 @@ private static string Version return versionString.InformationalVersion; } } + + private static readonly HashSet errorsToIgnore = new HashSet + { + "CS7027", // Code signing failure + "CS1589", // XML referencing not supported + "CS1569" // Error writing XML documentation + }; + + /// + /// Retrieves the diagnostics from the compilation, filtering out those that should be ignored. + /// + protected List GetFilteredDiagnostics() => + compilation is not null + ? compilation.GetDiagnostics() + .Where(e => e.Severity >= DiagnosticSeverity.Error && !errorsToIgnore.Contains(e.Id)) + .ToList() + : []; } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/StandaloneAnalyser.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/StandaloneAnalyser.cs index ff3c2889bc99..b940b02cb5c1 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/StandaloneAnalyser.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/StandaloneAnalyser.cs @@ -13,6 +13,14 @@ public StandaloneAnalyser(IProgressMonitor pm, ILogger logger, PathTransformer p { } + private void LogDiagnostics() + { + foreach (var error in GetFilteredDiagnostics()) + { + Logger.LogDebug($" Compilation error: {error}"); + } + } + public void Initialize(string outputPath, IEnumerable<(string, string)> compilationInfos, CSharpCompilation compilationIn, CommonOptions options) { compilation = compilationIn; @@ -20,6 +28,7 @@ public void Initialize(string outputPath, IEnumerable<(string, string)> compilat this.options = options; LogExtractorInfo(); SetReferencePaths(); + LogDiagnostics(); } } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/TracingAnalyser.cs b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/TracingAnalyser.cs index 8a9856f1d31d..9f2a1256f1a1 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Extractor/TracingAnalyser.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Extractor/TracingAnalyser.cs @@ -136,11 +136,7 @@ internal static string GetOutputName(CSharpCompilation compilation, private int LogDiagnostics() { - var filteredDiagnostics = compilation! - .GetDiagnostics() - .Where(e => e.Severity >= DiagnosticSeverity.Error && !errorsToIgnore.Contains(e.Id)) - .ToList(); - + var filteredDiagnostics = GetFilteredDiagnostics(); foreach (var error in filteredDiagnostics) { Logger.LogError($" Compilation error: {error}"); @@ -148,7 +144,7 @@ private int LogDiagnostics() if (filteredDiagnostics.Count != 0) { - foreach (var reference in compilation.References) + foreach (var reference in compilation!.References) { Logger.LogInfo($" Resolved reference {reference.Display}"); } @@ -156,12 +152,5 @@ private int LogDiagnostics() return filteredDiagnostics.Count; } - - private static readonly HashSet errorsToIgnore = new HashSet - { - "CS7027", // Code signing failure - "CS1589", // XML referencing not supported - "CS1569" // Error writing XML documentation - }; } } diff --git a/csharp/ql/lib/change-notes/2025-11-17-compiler-error-debug.md b/csharp/ql/lib/change-notes/2025-11-17-compiler-error-debug.md new file mode 100644 index 000000000000..082f4562615e --- /dev/null +++ b/csharp/ql/lib/change-notes/2025-11-17-compiler-error-debug.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* Compilation errors are now included in the debug log when using build-mode none.