SonarQube v9.6.1
Tool ‘dotnet-coverage’ was reinstalled with the latest stable version (version ‘17.5.0’).
Tool ‘dotnet-sonarscanner’ was reinstalled with the latest stable version (version ‘5.8.0’).
Visual Studio 2022 Target Framework “net6.0”
I’m new to C# scanning with SonarQube so I’m working on a simple test project with 1 “hello world” C# source file and 1 unit test source file.
I’ve followed the information on SonarScanner for .NET | SonarQube Docs.
FIRST, I execute dotnet sonarscanner begin
with a bunch of parameters. Here is a masked version of my command:
dotnet sonarscanner begin /k:"MY-KEY" /d:sonar.moduleKey="MY-MODULE-KEY" /d:sonar.login="TOKEN" /d:sonar.verbose="true" /d:sonar.host.url="https://my.sonarqube.server" /d:sonar.analysis.mode="publish" /d:sonar.scm.disabled="true" /d:sonar.sources="src/PROJECT/SRC-DIR" /d:sonar.tests="tests/PROJECT.TESTS/SRC-DIR" /d:sonar.dotnet.excludeTestProjects="true" /d:sonar.cs.vscoveragexml.reportsPaths="coverage-reports/*.xml"
SECOND, I run dotnet build
and dotnet-coverage
to build and test the solution.
THIRD, I execute dotnet sonarscanner end
to publish to SonarQube. Since this command has only two additional arguments, I won’t show a masked version of the command.
Everything seems to be working OK until the THIRD step.
The FIRST step executes without errors and it ends with Pre-processing succeeded.
The SECOND step run without errors and it ends with 1>Done Building Project “C:\projects\MyProject.sln” (default targets).
But for the THIRD step, it seems to start ok with…
SonarScanner for MSBuild 5.8
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
…it does a bunch of stuff then finally fails with:
ERROR: Error during SonarScanner execution
File src/PROJECT/SRC-DIR/Program.cs can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
Process returned exit code 1
The SonarScanner did not complete successfully
Post-processing failed. Exit code: 1
I’m a newbie to .NET C# scanning so I’m kind of stuck at this point. The error message is pretty clear, I just don’t have much experience with sonarscanner to troubleshoot what it is doing. In the FIRST step, I set /d:sonar.sources="src/PROJECT/SRC-DIR"
as the only source I want to scan. It has only 1 source file Program.cs
and that file doesn’t exist anywhere else.
During the THIRD step, I see output from sonarscanner that seems to indicate it is indexing files multiple times. This is what the (masked) output looks like:
INFO: Indexing files...
INFO: Project configuration:
INFO: Excluded sources: pom.xml
INFO: Indexing files of module 'PROJECT'
INFO: Base dir: C:\SOLUTION\src\PROJECT
INFO: Excluded sources: pom.xml
INFO: Indexing files of module 'PROJECT.TESTS'
INFO: Base dir: C:\SOLUTION\tests\PROJECT.TESTS
DEBUG: Test paths: SRC-DIR/ProgramTest.cs
INFO: Excluded sources: pom.xml
DEBUG: 'tests/PROJECT.TESTS/SRC-DIR/ProgramTest.cs' generated metadata as test with charset 'UTF-8'
DEBUG: 'tests\PROJECT.TESTS\SRC-DIR\ProgramTest.cs' indexed as test with language 'cs'
INFO: Indexing files of module 'PROJECT'
INFO: Base dir: C:\SOLUTION\src\PROJECT
DEBUG: Source paths: SRC-DIR/Program.cs
INFO: Excluded sources: pom.xml
DEBUG: 'src/PROJECT/SRC-DIR/Program.cs' generated metadata with charset 'UTF-8'
DEBUG: 'src\PROJECT\SRC-DIR\Program.cs' indexed with language 'cs'
INFO: Indexing files of module 'SONARQUBE-PROJECT-KEY'
INFO: Base dir: C:\SOLUTION
DEBUG: Source paths: src/PROJECT/SRC-DIR
DEBUG: Test paths: tests/PROJECT.TESS/SRC-DIR
INFO: Excluded sources: pom.xml
DEBUG: 'src/PROJECT/SRC-DIR/Program.cs' generated metadata with charset 'UTF-8'
I don’t know why it’s indexing the same thing multiple times, but could this the source of the problem?
Any help would be appreciated.