diff --git a/analyzers/src/SonarAnalyzer.Common/AnalysisContext/SonarAnalysisContextBase.cs b/analyzers/src/SonarAnalyzer.Common/AnalysisContext/SonarAnalysisContextBase.cs index c7c86996388..144c6b41a3a 100644 --- a/analyzers/src/SonarAnalyzer.Common/AnalysisContext/SonarAnalysisContextBase.cs +++ b/analyzers/src/SonarAnalyzer.Common/AnalysisContext/SonarAnalysisContextBase.cs @@ -126,8 +126,10 @@ public bool HasMatchingScope(DiagnosticDescriptor descriptor) } private bool FileIsIncludedInAnalysis(SonarLintXmlReader sonarLintXml, string filePath) => - ProjectConfiguration().ProjectType != ProjectType.Unknown // If ProjectType != 'Unknown' we are in S4NET context and all files are analyzed. - // If ProjectType == 'Unknown' then we are in SonarLint or NuGet context and we need to check if the file has been excluded from analysis through SonarLint.xml. + // If ProjectType != 'Unknown' we are in S4NET context and all files are analyzed. + // If ProjectType == 'Unknown' then we are in SonarLint or NuGet context and + // we need to check if the file has been excluded from analysis through SonarLint.xml. + ProjectConfiguration().ProjectType != ProjectType.Unknown || (FileInclusionCache.GetValue(Compilation, _ => new()) is var cache && cache.GetOrAdd(filePath, _ => IsFileIncluded(sonarLintXml, filePath)));