1

The scan seems to run fine but in Sonarcloud we can browse the code files under the Code tab but there are no scan results. In another project containing both c# and typescript code, the typescript (and css etc) is analyzed but not the c# code.

We are building **/*.sln and not *.csproj and are using the "normal" build steps.

enter image description here

Mathias Rönnlund
  • 4,078
  • 7
  • 43
  • 96

1 Answers1

2

The issue message “The main branch has no lines of code.” caused by C#/.net core require a dedicated scanner. See this doc which announced by SonarCloud: SonarScanner for MSBuild.

The SonarScanner for MSBuild is the recommended way to launch a SonarQube or SonarCloud analysis for projects/solutions using MSBuild or dotnet command as build tool.

Since the extension has embeds the SonarScanner for MSBuild, just ensure the way of analysis should be chosen as the shown below.

enter image description here

And also, since I could not get clearly know what's your csproj and sln files look like. I share my completed code in Github, you can refer to it: Sonar-Sample-Test.

Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35
  • Is SonarScanner also applicable from SonarCloud or only for SonarQube? – Mathias Rönnlund Sep 09 '19 at 11:20
  • Applicable for all. – Mengdi Liang Sep 09 '19 at 11:29
  • Can you elaborate? Sonarscanner seems to be something you have to download and install. How can I do that in Sonarcloud? – Mathias Rönnlund Sep 09 '19 at 11:47
  • As I mentioned in the answer. The Scanner has been embed with the Sonar extension of Azure Devops. After you install the extension, the scanner can be used normally. – Mengdi Liang Sep 09 '19 at 12:10
  • Hi, @MathiasR. How the things going? Could you get sonar scan result successfully now? Does my github code can help you achieve that? Feel free to share us your process:-) If still has puzzle thus other SO and me can help you. – Mengdi Liang Sep 11 '19 at 01:15
  • I also created a test project that works. Now I took my existing project that doesn't work, and sent the results here https://sonarcloud.io/dashboard?id=DotnetCoreTest but no problems are found. Can you check? – Mathias Rönnlund Sep 11 '19 at 06:16
  • According to this result, it means the issue of scanner has been disappeared. But now, the new issue is no code coverage data. This should caused by your test script. Your test script doesn't cover the code in your ErpChangeTracker. You'd better share your completed script. You can refer to my result: https://sonarcloud.io/code?id=mengdi0301 – Mengdi Liang Sep 11 '19 at 06:22
  • I could not know your test script, you'd better share it. – Mengdi Liang Sep 11 '19 at 06:26
  • I created a new build pipeline for the project where I just used the classic editor and the template ".NET Core with SonarCloud". This worked for a test project I created from scratch. With this template we see the current behaviour where the code is found and uploaded to sonarcloud but there is no coverage. What can cause this? – Mathias Rönnlund Sep 11 '19 at 11:52
  • Your test script. You can check the log of dotnet test task to see whether it is test truly. No coverage data means your test code does not cover your script. – Mengdi Liang Sep 11 '19 at 11:56
  • So this is now, quite embarrassingly, solved. After changing to MSBuild I started seeing test results but all meters shows 0 bugs, code smells etc. I assumed that this was because the code wasn't actually analyzed but as it turned out, in this project we don't have a single problem. – Mathias Rönnlund Sep 11 '19 at 13:26
  • @MathiasR Yeah, the issue you meet firstly does not has relevant with your project, just caused by your pipeline configuration. But now, 0 bug, code smell or other means your code does not be covered by your test script. You’d better deep check your code, and if help, you can also refer to my github code( it is a very simple sample). – Mengdi Liang Sep 11 '19 at 13:31
  • I added some artifical bugs, like a string property called Password, and Sonarcloud listed this as a problem. – Mathias Rönnlund Sep 11 '19 at 14:00