SonarQube CLI Question - File indexing errors

Must-share information (formatted with Markdown):

  • Using the latest dotnet-sonarscanner version
  • dotnet-sonarscanner being used in a Dockerfile
  • Trying to achieve a simple code scan

I have the following directory structure in my C# project:

└── ProjectFolder/
    ├── Dockerfile
    ├── Solution.sln
    ├── Source/
    │   └── ...
    └── Tests/
        └── ...

In my Dockerfile, I copy over this exact structure:

WORKDIR /ProjectFolder
RUN mkdir -p Source
RUN mkdir -p Tests
COPY --from=build-env /ProjectFolder/Solution.sln Solution.sln
COPY --from=build-env /ProjectFolder/Source ./Source
COPY --from=build-env /ProjectFolder/Tests ./Tests

and then I run the following dotnet-sonarscanner command from the base directory:

RUN /root/.dotnet/tools/dotnet-sonarscanner begin \
    /k:"ProjectFolder" \
    /d:sonar.login="xxxxxxxxxxxxx" \
    /"yyyyyyyy" \
    /d:sonar.cs.opencover.reportsPaths=coverage.xml \
    /d:sonar.exclusions=**/bin/**/*,**/obj/**/* \
    /d:sonar.sources=Source \

And I get this error (with the accompany indexing logs):

37.85 INFO: Indexing files...
37.85 INFO: Project configuration:
37.85 INFO:   Excluded sources: **/bin/**/*, **/obj/**/*
37.85 INFO: Indexing files of module 'Tests'
37.85 INFO:   Base dir: /ProjectFolder/Tests
37.85 INFO:   Test paths: Configuration/BasicAuthOptionsTests.cs, Configuration/HealthOpt...
37.85 INFO:   Excluded sources: **/bin/**/*, **/obj/**/*
37.91 INFO: Indexing files of module 'Source'
37.91 INFO:   Base dir: /ProjectFolder/Source
37.91 INFO:   Source paths: Configuration/BasicAuthOptions.cs, Configuration/HealthOption...
37.91 INFO:   Excluded sources: **/bin/**/*, **/obj/**/*
37.96 INFO: Indexing files of module 'Source'
37.96 INFO:   Base dir: /ProjectFolder
37.96 INFO:   Source paths: Source
37.96 INFO:   Test paths: Tests
37.96 INFO:   Excluded sources: **/bin/**/*, **/obj/**/*
File Source/Services/XXXXX.cs can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

I see that the module Source is being indexed twice. How can I prevent this? What am I doing wrong here? I’ve read most of Narrowing the focus with an analysis scope but cannot figure it out…


Welcome to the community!

TBH, I’m a bit confused about the file structure after you’ve done your copying. But what I really don’t understand is why you feel the need to do the copying in the first place. Why not just cd into ProjectFolder and run the analysis there?

But anyway…

Part of what happens during the begin and build parts of the process is identifying your source and test files. I’m guessing that your explicit specification of sonar.sources and sonar.tests is causing the double indexing - once for your specification and once for the ‘found’ files.