SonarSource / sonar-scanner-msbuild

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

No metrics or issues are imported for a ASP .NET 6 MVC project #1116

Closed andrei-epure-sonarsource closed 2 years ago

andrei-epure-sonarsource commented 3 years ago

Description

For a simple ASP .NET MVC 6 project, there are no metadata (e.g. LOCs, highlighting) and no issues imported in SonarCloud.

Repro steps

Please provide the steps required to reproduce the problem

  1. Analyze https://github.com/andrei-epure-sonarsource/aspnet5mvc-reproducer (commit 917f627) on SonarCloud. Make sure to run dotnet build --no-incremental .\AspNetCoreMvc5.sln to rebuild.

  2. See the report - no metrics, no issues. The same project, if we change net5 as Target Framework in the csproj will have issues and metrics - see here).

Expected behavior

Should import issues and metrics.

Actual behavior

Please note that the console logs does contain the issues for .NET 6 , they just don't get reported. This makes this issue very similar to #1040.

C:\Workspace\external-projects\2021-11-22-s4net-net6\aspnet5mvc-reproducer\AspNetCoreMvc5\Program.cs(12,18): warning S1118: Add a 'protected' constructor or the 'static' keyword to the class declaration. [C:\Workspace\external-projects\2021-11-22-s4net-net6\aspnet5mvc-reproducer\AspNetCoreMvc5\AspNetCoreMvc5.csproj] C:\Workspace\external-projects\2021-11-22-s4net-net6\aspnet5mvc-reproducer\AspNetCoreMvc5\Controllers\HomeController.cs(14,50): warning S4487: Remove this unread private field '_logger' or refactor the code to use its value. [C:\Workspace\external-projects\2021-11-22-s4net-net6\aspnet5mvc-reproducer\AspNetCoreMvc5\AspNetCoreMvc5.csproj] 2 Warning(s) 0 Error(s)

However during the end step

INFO: Sensor C# [csharp] WARN: No protobuf reports found. The C# files will not have highlighting and metrics. You can get help on the community forum: https://community.sonarsource.com WARN: No Roslyn issue reports were found. The C# files have not been analyzed. You can get help on the community forum: https://community.sonarsource.com INFO: Found 1 MSBuild C# project: 1 MAIN project. INFO: Sensor C# [csharp] (done) | time=2ms

Known workarounds

None.

Related information

guitax commented 2 years ago

I have the same (or similar) issue with .NET 6 Razor Class Libraries, where .csproj have <Project Sdk="Microsoft.NET.Sdk.Razor">.

For each RCL project we have these logs:

No Code Analysis ErrorLog file found at /task/src/.sonarqube/out/8/Issues.json. ... INFO: Sensor C# Properties [csharp] WARN: Analyzer working directory does not exist: '/task/src/.sonarqube/out/8/output-cs'. Analyzer results won't be loaded from this directory. WARN: No Roslyn issues report found for this project. INFO: Sensor C# Properties [csharp] (done) | time=0ms

and looking at .sonarqube/out, the related folders all have an unexpected .tmp suffix in the name (but all analysis files are there) image

Related information

csaba-sagi-sonarsource commented 2 years ago

For Net5 razor projects there are two compilations one core and one razor. So, the core compilation creates the folders with numeric names then a task renames them to numeric.tmp. After it the razor compilation runs which creates again numeric names and after that compilation another task renames the numeric ones to numeric.razor and the numeric.tmp back to numeric. For Net6 the default behavior is to use SourceGenerators for razor projects and in that case there is only one compilation and our logic with folder renaming fails. Until the issue is fixed, as a workaround the following property will disable the usage of SourceGenerators : <UseRazorSourceGenerator>false</UseRazorSourceGenerator>