.net-coresonarlinttarget-framework

Sonarlint dotnetcore2 multiple targetframeworks gives duplicate warnings


I'm using SonarLint for a dotnetcore 2 project, this project also target net461. Each warning gets reported for each targetframework, resulting in duplicate warnings.

I tried to fix this by adding a condition to the analyzer package ref, this didn't work:

<PackageReference Include="SonarAnalyzer.CSharp" Version="6.7.1.4347" Condition="'$(TargetFramework)'=='netcoreapp2.0'">
  <PrivateAssets>all</PrivateAssets>
</PackageReference>

Is there any way to setup sonarlint for 1 targetframework only?

Example: Duplicate warning example


Solution

  • This looks indeed a bit weird but this is the default behavior of roslyn-based analyzers. From my tests the behavior is conform with the one produced by StyleCope.Analyzers, Roslynator, CodeCracker and so on.

    I haven't found any ticket on Roslyn repository regarding a change of this behavior.