SonarSource / sonar-scanner-msbuild

SonarScanner for .NET
http://redirect.sonarsource.com/doc/msbuild-sq-runner.html
GNU Lesser General Public License v3.0
362 stars 143 forks source link

Sonarscanner not analyzing netcoreapp2.2 #759

Closed armourshield closed 5 years ago

armourshield commented 5 years ago

I am trying sonarqube on my aspnetcore2.2 project.

The project uses MSbuild version - 16.1.76.45076.

When I run the official dotnet-sonarscanner tool - version 4.6.2, only CSS code is getting analyzed and not the C#, Javascript and other codes being analyzed from the project.

I have tried the following,

Using Different MSBuilds:

I have tested with different MSBuild versions as there was a change in MSBuild from aspnetcore2.1 to aspnetcore2.2

Versions tried

Both returned with the same result of not analyzing any files other than CSS files.


Using Different Sonarscanner tools:

I also went ahead and checked with different sonarscanner tools

Sonarscanner tools used

All resulted in the same result of no file other than CSS files being analyzed


Verification of Project Settings in Sonarqube:

To check if the server-side is setup properly, I tested on different frameworks of aspnetcore

Tested frameworks

Only in aspnetcore2.2, I am facing this problem.

aspnetcore2.0, aspnetcore2.1 were analyzed for all the files C#, HTML, Javascript and CSS

These were also tested with different MSBuild versions and sonarscanner tools.


CLI Command tried

These are the CLI used for the replication of the problem

All the below commands didn't return an error.

Only the CSS files were getting analyzed for aspnetcore2.2 projects

The commands were tried in different combination as described above to replicate version problems

dotnet sonarscanner begin /k:"<projectname>" /d:sonar.host.url="<sonarqserver>" /d:sonar.login="<usertoken>"
dotnet build
dotnet sonarscanner end /d:sonar.login="<usertoken>"
dotnet <pathto Sonarscanner.MSBuild.dll> begin /k:"<projectname>" /d:sonar.host.url="<sonarqserver>" /d:sonar.login="<usertoken>"
dotnet build
dotnet <pathto Sonarscanner.MSBuild.dll> end /d:sonar.login="<usertoken>"
dotnet sonarscanner begin /k:"<projectname>" /d:sonar.host.url="<sonarqserver>" /d:sonar.login="<usertoken>"
<pathto MSBuildversion.exe> build
dotnet sonarscanner end /d:sonar.login="<usertoken>"

The expected result is

The actual result is

duncanp-sonar commented 5 years ago

@armourshield I've just unfolded new ASP.Net 2.1 and 2.2 projects and analysed them from the command line using:

dotnet sonarscanner begin...
dotnet build
dotnet sonarscanner end

... and both projects were analysed as expected (i.e. results for JS, CSS, HTML and C#)

Questions:

armourshield commented 5 years ago
duncanp-sonar commented 5 years ago

Ok. If the expected files are in listed FilesToAnalyze.txt then it means the Sonar targets were correctly picked up during the build phase and they collected the data correctly.

armourshield commented 5 years ago
  1. The indexing of the file was done and all the files including the .cs, .cshtml (Razor Pages), minified js, minified CSS, CSS and others were picked up during it.
  2. During Indexing, the .cshtml files were recognized as 'web' and all the other C# code as 'cs' language
  3. On the Run Sensors Stage, Only the following Sensors were used
    DEBUG: Sensors : SonarCSS Metrics -> SonarCSS Rules -> JaCoCo XML Report Importer -> C# Properties -> JavaXmlSensor -> XML Sensor.

    This starts the CSS Analysis, by default, it is using node, -v, v8.12.0. The following node processed is used for .cshtml files too.

  4. From the rest of the Sensors, got the following output

For XML, the file was indexed during the beginning of Sonar scanner. This file is our own file of unrelated format analysis, not a part of sonarqube

Sensor JavaXmlSensor [java]
2 source files to be analyzed
'AnalysisFile.xml' generated metadata as test  with charset 'UTF-8'
'wwwroot/XML/AnalysisFile_16-04-2019.xml' generated metadata as test  with charset 'UTF-8'
Sensor JavaXmlSensor [java] (done) | time=1284ms

For C#

Sensor C# Properties [csharp]
Analyzer working directory '<ProjectDir>\.sonarqube\out\0\output-cs' contains 5 .pb file(s)
Found Roslyn issues report
Sensor C# Properties [csharp] (done) | time=15ms
  1. Run sensors runs again with lowercase of the project-key. This time no file to analyze comes up in SensorC# as below
Sensor C# [csharp]
No files to analyze. Skip Sensor.
Sensor C# [csharp] (done) | time=0ms
  1. Run sensors runs on the project, These time the following output comes out as below
Java CPD Block Indexer' skipped because there is no related file in current project
Sensor Zero Coverage Sensor (done) | time=0ms
  1. After this, a list of .cs and .cshtml files gets the following
<filename>.cshtml generated metadata as test  with charset 'UTF-8'
<filename>.cs generated metadata as test  with charset 'UTF-8'
  1. At the very end following WARN: are given before posting the analysis
WARN: Missing blame information for the following files
WARN:   * SonarQube.Analysis.xml
WARN: This may lead to missing/broken features in SonarQube
  1. And the job is posted

The issue still persists

armourshield commented 5 years ago

I wanted to test the environment if it is right with the same tools

Created new projects for dotnetcore2.1 and dotnetcore2.2

When running the sonarq analysis it ran perfectly analyzing all the files

duncanp-sonar commented 5 years ago

@armourshield I see you've created duplicate topics in the community forum and on Stack Overflow, so I'm going to close this issue to avoid duplication of effort.

armourshield commented 5 years ago

I will remove it from other forums, shall we continue the discussion here

duncanp-sonar commented 5 years ago

The community forum is a better location: it is monitored by more people who might be able to answer, or which might be interested in the answer.