Zero Code Coverage after changing csproj to sdk file format

I switched my project from “old” format (ToolsVersion="12.0") to sdk format (Sdk="Microsoft.NET.Sdk.WindowsDesktop"). After that the code coverage is calculated with 0%.
In addition to this change the following items were changed in timely correlation, even I guess there are irrelevant:

  • SQ Server update from 8.8.0 to 8.9.1
  • update of referenced NuGet packages, like xunit.runner.visualstudio from 2.4.1 to 2.4.3
    The analyzer remains unchanged: SonarScanner for MSBuild 5.0.4.

I analyzed the logfiles of the first analysis (old format, coverage around 90%) and new analysis (sdk format, coverage 0%) and identified the following differences:

  • New Warning: File 'C:\Users\***\.nuget\packages\***\1.1.18\build\net40\***.dll' is not located under the root directory 'c:\buid\_work\298\s' and will not be analyzed. This should not be relevant because this not in focus for the analyzed project.
  • The Sensor C# Tests Coverage Report Import [csharp] reports
    DEBUG: Pattern matcher extracted prefix/absolute path 'c:\buid\_work\298\s\TestResults' from the given pattern 'c:\buid\_work\298\s/TestResults/**/*.coveragexml'.
    In the successful analysis the matcher extracted the path “c:\build\_work\317” without “s/TestResults” with similar input:
    DEBUG: Pattern matcher extracted prefix/absolute path 'c:\build\_work\317' from the given pattern 'c:\build\_work\317\s/TestResults/**/*.coveragexml'.
    I guess this is interesting but I do not have an explanation for the behavior. (Maybe this is not relevant because this output is only from coveragexml file identification.)
  • Later the cs files from test project are identified and listed to be ignored. This results now in the following summary:
    DEBUG: The total number of file count statistics is '25'.
    INFO: Coverage Report Statistics: 25 files, 0 main files, 0 main files with coverage, 25 test files, 0 project excluded files, 0 other language files.
    The Code Coverage report doesn't contain any coverage data for the included files. Troubleshooting guide: https://community.sonarsource.com/t/37151
    In the successful analysis this looks like follows:
    DEBUG: The total number of file count statistics is '80'.
    INFO: Coverage Report Statistics: 80 files, 55 main files, 55 main files with coverage, 25 test files, 0 project excluded files, 0 other language files.
    The cs files from “real” project are not identified anymore.

I checked the mentioned Troubleshooting Guide but did not identify helpful information for my problem:

  • The files to be analyzed are listed with indexed with language 'cs'
  • The coverage file is identified and converted to converagexml by the analyzer:
    INFO: Parsing the Visual Studio coverage XML report c:\buid\_work\298\s\TestResults\***_2021-08-31_10_38_19\In\***\***_2021-08-31.10_38_11.coveragexml

I have other projects analyzed correctly in sdk file format. But I think this is the most relevant change (of identified differences).

Hi @lg2de,

There seems to be an issue with project type detection. Are there any issues found on your projects?

Could you please run the analysis in verbose mode (by adding /d:sonar.verbose=true parameter to the begin step) and share with us the output of the begin and end steps?

Thanks,
Costin

Please find attached the pipelines output (with enabled verbose output) for begin and end analysis.

begin.log (10.8 KB)
end.log (254.2 KB)

Could you please check if the coverage file (c:\build\_work\378\s\TestResults\*****_BUILD-RD-TA1_2021-08-31_11_40_47\In\BUILD-RD-TA1\*****_BUILD-RD-TA1_2021-08-31.11_40_40.coveragexml) was generated correctly and if it has statistics for the LogFileViewer project? If possible, could you also attach that file?

The coverage import sensor is not logging anything related to LogFileViewer project files. Instead, it finds coverage entries related to xunit sources:

Line 1320: 11:41:08.045 DEBUG: Did not find deterministic source path in ‘C:\Dev\xunit\xunit\src\xunit.execution\Sdk\TestClassException.cs’. Will skip this coverage entry. Verify sonar.sources in .sonarqube\out\sonar-project.properties.

The xunit sources are skipped by the sensor since they are not part of the project being analyzed.

1 Like

As far as I can tell, LogFileViewer was correctly detected as a MAIN project (not a test one) and the generated file list from sonar-project.properties also contains the correct list of files. I assume that the coveragexml report does not have the right content.

This was the right clue!
The coveragexml file does not contain data about the main project.
But not the conversion is not causing the problem. The converage file does not contain the information too.

The root cause was that the main project was packed with Fody.
For the moment I cannot explain why code coverage was working before where Fody was already active.

Thanks for your support!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.