Analyze test projects using SonarAnalyzer.CSharp in Visual Studio


I am trying to analyze test project using SonarAnalyzer.CSharp in Visual Studio. I added SonarAnalyzer.CSharp package to project and customized ruleset. Rule S1481 and S2221 should return errors when violated.

Error for S1481 is detected correctly, but error for rule S2221 is not visible is Error Tab in Visual Studio after build.

I assume that reference to Microsoft.VisualStudio.TestPlatform.TestFramework or other test related packages in my test project cause SonarAnalyzer to skip certain rules. After removing TestFramework reference I can see errors for both rules S1481 and S2221 in Error Tab in Visual Studio after build.

Based on documentation I was trying to add the following parameter


to .csproj file but it does not help in that case. However, it allowed to analyze test project during PR and all violated rules are visible in SonarCloud.

Is there any way to force SonarAnalyzer.CSharp to analyze and list all violated rules in test project in Visual Studio?

Hi @KamilT,

Thanks a lot for your feedback.

Indeed, as you observed, the SonarQubeTestProject property is not considered during analysis in Visual Studio but only when the scanner is involved. Our plan, in the near future (Q1), is to implement this in SonarLint (VisualStudio and Rider) in order to allow consistent results in pipeline and IDE.


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.