C# Files are not being analyzed with Sonar Cloud and Azure DevOps pipeline

@Phaneendra_kotha,

Your build log has dozens of warnings like the following:

Essentially, it means the analyzers couldn’t be run because the version of the Microsoft CodeAnalysis assemblies (i.e. Roslyn) being used by the compiler is too old. That’s surprising because you seem to be using the Visual Studio 2017 build task, and VS 2017 shipped with Roslyn v2.0.

However, if we look at the version of the compiler that is being invoked during your build, it’s actually using Roslyn version 1.0:

My guess is that your project has a reference to v1.0 of the Microsoft.Net.Compilers NuGet package, so that’s version that being used during the build → the analyzers won’t work.

It’s not normally necessary to reference the Microsoft.Net.Compilers NuGet package directly; MSBuild and the C# compiler are backwards compatible, so newer versions of the compiler tools can be used to build old code that targets an older version of the framework.

If you do need to reference the Microsoft.Net.Compilers package directly and want to use the SonarC# analysis rules then you will need to change your package to reference to point to at least v1.3.2 of the Microsoft.Net.Compilers.

3 Likes