Analyser C# not Working

Yes.

Hi @nmathieu

Which version of MSBuild are you using ? What does contain the task group ? is there any “standard” msbuild task on it ?

Thanks.

the task group

I use the last version of MsBuild, with Visual studio 2019 !

Hi,
i try with a simple pipeline , same result

Do you see any kind of Sonar-related logs in this build solution task ?

Here is the log File of the build
log.txt (81.3 KB)

Hi @nmathieu

Sorry for the late reply.

I noticed some inconsistency between the auto-generated folder when building. For instance, on your last build log, it says “D:\agent_work\64\s” and on the run code analysis logs, analysis is made on “D:\agent_work\60\s”. Is that on purpose ? Can you check that on your full pipeline execution, everything goes in the same folder ?

Thanks.

Hello
Thx for your reply
Here is the Full Log of My Build Pipeline logs_7733.zip (602.4 KB)

Thanx :slight_smile:

Thanks for the logs. It looks like the Sonar Scanner for MSBuild targets are being executed during the build, but for some reason the SonarC# analyzer is not being executed. The SonarC# analyzer is responsible for calculating the lines of code per file as well as raising analysis issues, which is why no lines of code are being reported in SonarQube.

To help work out what is happening, could you try the following please?

  • temporarily remove your .editorconfig file and run the CI build to see if that makes a difference.

  • with the .editorconfig present, run a CI build with diagnostic logging enabled and send us the build logs (i.e. pass /v:diag as argument to MSBuild). That should give us a better idea of why csc.exe is not executing the SonarC# analyzer. If you could share your .editorconfig file that would also be useful.

Thanks.

1 Like

Hello,
the file .editorconfig present in the solution?

Thx :slight_smile:

Yes; from the logs it looks like it is at the root of the source folder.

logs_7777 (1).zip (2.6 MB)

The log without the .editorconfig.

I upgrade sonarqube to version 8.5.
without the .editorconfig the warning is different:
WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the Scanner for MSBuild 4.x, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html.

After deleting I cannot find the .editorconfig file, who generates it?

The final message was changed in SQ 8.5. Since you use Scanner for MsBuild, this message is a side effect of the C# analyzer not being triggered during the csc build.

Do you have any *.targets files in your solution?

.editorconfig is usually added manually. VS can generate it when you do some configuration changes. You should check your backup to see the original file.

yes, I have a lot of * .targets file.
In particular one concerning my target project:

Nova.Model.csproj.nuget.g.targets

<?xml version="1.0" encoding="utf-8" standalone="no"?> $(MSBuildAllProjects);$(MSBuildThisFileFullPath)

and more :slight_smile:

Thanks for the detailed logs.

According to the logs, the Sonar analyzers are being removed by the standard Microsoft target DisableAnalyzers. My guess is that you are setting RunAnalyzersDuringBuild or RunAnalyzers to false somewhere in your project/target files.

Try adding /p:RunAnalyzersDuringBuild=true is the MSBuild Arguments section of the Azure DevOps build step.

3 Likes

I love you :slight_smile:
It work .

2 Likes

:+1:

FYI there’s a ticket in the scanner backlog (#829) to look at handling this situation automatically.

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