Error SonarScanner C# and VB.NET

Greetings, I searched a lot before opening this topic and unfortunately I didn’t find a solution.

I recently installed Sonarqube Community on an AWS instance

I downloaded the SonarScanner through this link, tested the .Net 5.0 packages and also the .Net 4.6, made the reference in environment variables and then ran the solution in Visual Studio, and then did the scan as directed by Sonarqube.

I used the following commands:


"SonarScanner.MSBuild.exe begin /k: "aed2" /d:sonar.host.url="http://ip-server-sonarqube" /d:sonar.login="token""


MsBuild.exe /t:Rebuild


SonarScanner.MSBuild.exe end /d:sonar.login="token"

It is understood that the words token and ip-server-sonarqube have been replaced because they are sensitive information.

This is the error I get when I finish the scanning steps:

INFO: ------------- Run sensors on project
INFO: C# sensor [csharp]
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 SonarScanner for .NET 5.x or higher, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html
INFO: C# sensor [csharp] (done) | time=0ms
INFO: VB.NET sensor [vbnet] (done)
WARN: Your project contains VB.NET files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html
INFO: VB.NET sensor [vbnet] (done) | time=0ms

I also tested with jenkins and get the same error with both, can you help me?

Hi,

Welcome to the community!

That’s the error you get when you’re not using the SonarScanner for .NET, which your command list indicates you are using. The only thing that catches my eye in your command is the space between /k: and the key string. But I wouldn’t expect it to have that result.

Could you provide the full analysis log, starting from the analysis command?

 
Ann

Hello, thank you for the greetings.

I think the space was added wrongly, I will leave a screenshot of the project analysis

I would like to send you another piece of the log by private message, is that possible ?
I believe this is more sensitive information.

Hi,

Feel free to redact your analysis log as needed.

 
Ann

1 Like

Ann, I would also like to point out that I tried to run the scanner with jenkins, but also without success, I noticed only one variation: when I run it through jenkins it evaluates the whole project, both front end and back end.
When I run it locally in visual studio, it only scans the backend folders.
When I try to run it locally in another directory, it asks to run it in the solution’s directory.
I look forward to your help, thank you!

Hi,

Thanks for the log. As far as I can tell, you’re doing everything right. So I’ve referred this for more expert attention.

 
Ann

1 Like

Ok, thank you very much, is there anything I can do?
Or some other way to scan the code?
I would like to inform you that my project is made in NetFramework 4.6

Hello @ganncamp any answer?

Hello

I don’t fully get the problem - do I understand correctly that with some configuration/setup, the analysis runs correctly?

1 Like

Yes, and I have a similar situation when using both locally and on the server, the Scanner sees files but does not scan and refers to the fact that a scanner higher than version 5 is needed. But at the same time there is a 4.6 or 4.7 version of the scanner, Why does this happen?


1 Like

Hi Andrei, in the meantime I have continued my studies in sonarqube and realized that if I use the following command I can scan the frontend smoothly:

 sonar-scanner.bat -D "sonar.projectKey=name-project" -D "sonar.sources=." -D "sonar.host.url=ip-server-sonarqube" -D "sonar.login=token"

But to scan the backend I need to use another sequence of commands

SonarScanner.MSBuild.exe begin /k: "name-project" /d:sonar.login="token" /d:sonar.host.url="ip-server-sonarqube" 

MSBuild.exe /t:Rebuild /p:RunAnalyzersDuringBuild=true

SonarScanner.MSBuild.exe end /d:sonar.login="token"

But when I’m running on the backend, I run into that error mentioned a few messages above:

tab INFO: ------------- Run sensors on project
INFO: C# sensor [csharp]
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 SonarScanner for .NET 5.x or higher, see SonarScanner for .NET
INFO: C# sensor [csharp] (done) | time=0ms
INFO: VB.NET sensor [vbnet] (done)
WARN: Your project contains VB.NET files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see SonarScanner for .NET
INFO: VB.NET sensor [vbnet] (done) | time=0ms

So, I can’t get the scanning result for all files, I am still facing problems with some C# and VB.NET files.
Can you help me?
Obs:My project is in NetFramework 4.6

Hi @Paulo_Roberto,

RunAnalyzersDuringBuild parameter is by default set to true due to this, /p:RunAnalyzersDuringBuild=true is not needed.
More details here: Turn off code analysis - Visual Studio (Windows) | Microsoft Docs

This does not cause any harm though.

In your case it seems that either project detection or the file detection failed. Can you confirm that there are .Net projects in the solution and all these projects have code files (*.cs, *.vb)?

You should also try to provide the path to the *.sln file when running the MsBuild.exe /t:Rebuild command.

If this does not solve the problem, could you please run the analysis in verbose mode and send us the build and the analysis (end step) logs?

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"