Files being indexed twice

I’m learning how to integrate SonarCloud with Github Actions in a personal project. The Github repository that I am using can be accessed by clicking here.

The solution I am developing was created with version 8.0 of .NET. By default, all source code is present in the src directory. All test projects (unit, integration and functional) are present in the tests directory.

My Github Actions workflow that is integrating with SonarCloud is called Develop Workflow, and can be accessed by clicking here.

As my test and source code directories are separate, I followed the recommendations from the official SonarCloud documentation, and indicated their respective locations in the dotnet-sonarscanner begin command.

./.sonar/scanner/dotnet-sonarscanner begin /k:"lucasdirani_GithubActionsTest" /o:"tech-challenge-arquitetura-sistemas-net" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.sources="src/" /d:sonar.tests="tests/" /""

However, during the execution of the pipeline (the last execution I performed can be found by clicking here), for some reason the scanner is pointing out the indexing error shared right after.

ERROR: File src/Postech.PhaseOne.GroupEight.TechChallenge.Api/Setup/RepositorySetup.cs can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

I’m confused by the error since the RepositorySetup file is only being referenced in a single project in my solution.

I would like to ask for help to resolve the problem in question. I tried several alternatives, but the error persists regardless of what I do.

Hey there

When using the Scanner for .NET, there’s never a need to set these parameters because all the information can be collected from the project/solution files. Try removing them!

1 Like

Colin, thanks for the response.

The pipeline completed the scan without errors this time, but when I access my SonarCloud dashboard, not a single line of source code has been extracted from the solution.

The latest pipeline run can be accessed by clicking here.

Is there some configuration I’m forgetting to do?

      name: SonarCloud Scan
      runs-on: ubuntu-latest
      needs: build
        - name: Checkout code
          uses: actions/checkout@v3
            fetch-depth: 0

        - name: Setup .NET
          uses: actions/setup-dotnet@v3
            dotnet-version: '8.0.x'
        - name: Install Java 17
          uses: actions/setup-java@v3
            java-version: '17'
            distribution: 'temurin'

        - name: Cache SonarCloud packages
          uses: actions/cache@v3
            path: ~\sonar\cache
            key: ${{ runner.os }}-sonar
            restore-keys: ${{ runner.os }}-sonar

        - name: Cache SonarCloud scanner
          id: cache-sonar-scanner
          uses: actions/cache@v3
            path: .\.sonar\scanner
            key: ${{ runner.os }}-sonar-scanner
            restore-keys: ${{ runner.os }}-sonar-scanner

        - name: Install SonarCloud scanner
          if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
          run: |
            mkdir -p ./.sonar/scanner
            dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner

        - name: Install dotnet coverage
          run: dotnet tool install --global dotnet-coverage

        - name: Solution Scan
            SONAR_TOKEN: ${{secrets.SONAR_TOKEN}}
            GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
          run: |
           ./.sonar/scanner/dotnet-sonarscanner begin /k:"lucasdirani_GithubActionsTest" /o:"tech-challenge-arquitetura-sistemas-net" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /""
           dotnet build src/Postech.PhaseOne.GroupEight.TechChallenge.sln --no-incremental
           ~/.dotnet/tools/dotnet-coverage collect "dotnet test src/Postech.PhaseOne.GroupEight.TechChallenge.sln" -f xml -o "coverage.xml"
           ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

Is there any other way that I can integrate my pipeline with Sonar Cloud?
So far I haven’t been able to find a solution to the problem.

Good morning, I’m experiencing the same problem, have you had any updates on this error? managed to solve?


I am also experiencing same error. Though i dont have duplicate files, i see see the errors (for example: File Responses/UserDetail.cs can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files)

This is same error for both Angular App and dotNET app pipelines.

@Brenojgomes and @Ramesh_Babu, can you create new threads with details about versions, logs, scanner commands, analysis parameters, etc.? This message can be triggered a lot of different, unrelated ways.

@lucasdirani It looks like you’re analyzing a short-lived branch / pull request, which will only raise issues on changed lines of the branch/PR. If all you’re doing is editing Pipeline files, you won’t see any changes on your source code.

Once merged into your main branch, I’d expect that you see full results. You can also delete the branch and adjust your long-lived branch pattern. Upon reanalyzing the branch as a new branch, you’ll see full results (changed lines or not).