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 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
- MSBuild - 16.1.76.45076
- MSBuild - 15.1.0.0
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
- dotnet-sonarscanner - 4.6.2
- dotnet-sonarscanner - 4.6.0
- SonarScanner.MSBuild - 4.6.2 for aspnetcore2.0+
- SonarScanner.MSBuild - for aspnetcore 2.1.3
- .NETFramework4.6
All the above resulted in the same result of no files 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
- aspnetcore 2.0
- aspnetcore 2.1
- aspnetcore 2.2
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
- Analysis of C#, Javascript, CSS and HTML code
The actual result is
- Only analysis of CSS files
Edit 1
Answering the following questions
- Are the expected files listed in
.sonarqube\out\sonar-project.properties? - Add the property /d:sonar.verbose=true to the begin step and run the
analysis steps again. Then have a look at the output of the end step
for warnings (try searching the file name of one the files that
should have been analyzed, and for “C#”) - which version and edition of SonarQube are you using?
- which version of the SonarC# plugin?
-
Yes, they are present in the .sonarqube\out\sonar-project.properties
-
/d:sonar.verbose=true
to the beginning step was tested and went through the analysis, these are the key points observation from the output -
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.
-
During Indexing, the .cshtml files were recognized as ‘web’ and all the other C# code as ‘cs’ language
-
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.
- 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
- 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
- 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
- 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'
- 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
- And the job is posted
-
I am using Sonarqube 7.9 Community Edition
-
I am using the default plugin which gets downloaded with Sonarqube 7.9 Server - SonarC# - 7.15 (I am not sure if this is the same version getting installed as default in Sonarqube 7.9 Server
-
I tried the following steps for dotnetcore2.1, the C# and other files were analyzed
-
Also tried the following without Inhouse XML Analysis file if there was something breaking in analysis due to it.
The issue still persists