Dotnet Scanner is not recognized as the name of a cmdlet, function, script file, or operable program

Any idea how to resolve this error. I am using the tutorial provided and it was working before. But getting this error.

  • ALM used (GitHub)
  • CI system used (GitHub Actions)
  • Scanner command used when applicable (private details masked)
name: SonarQube
on:
  push:
    branches:
      - master
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  build:
    name: Build and analyze
    runs-on: windows-latest
    steps:
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          java-version: 17
          distribution: 'zulu' # Alternative distribution options are available.
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      - name: Cache SonarQube Cloud packages
        uses: actions/cache@v4
        with:
          path: ~\sonar\cache
          key: ${{ runner.os }}-sonar
          restore-keys: ${{ runner.os }}-sonar
      - name: Cache SonarQube Cloud scanner
        id: cache-sonar-scanner
        uses: actions/cache@v4
        with:
          path: .\.sonar\scanner
          key: ${{ runner.os }}-sonar-scanner
          restore-keys: ${{ runner.os }}-sonar-scanner
      - name: Install SonarQube Cloud scanner
        if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
        shell: powershell
        run: |
          New-Item -Path .\.sonar\scanner -ItemType Directory
          dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
      - name: Build and analyze
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        shell: powershell
        run: |
          .\.sonar\scanner\dotnet-sonarscanner begin /k:"project-key" /o:"myorg" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
          dotnet build
          .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
  • Languages of the repository: dotnet
  • Error observed:
The term '.\.sonar\scanner\dotnet-sonarscanner' is not recognized as the name 
of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, 
verify that the path is correct and try again.

Hey @amitkk

I took your GitHub Actions YML and plugged it into a new repo and while I made no effort to have it succeed, it did not fail the same way yours did.

(logs)

Can you share the raw log output like I have here?

I don’t know what changed, it was working previously :frowning:

I found the issue. There is something wrong with previous step

- name: Cache SonarQube Cloud scanner
        id: cache-sonar-scanner
        uses: actions/cache@v4
        with:
          path: .\.sonar\scanner
          key: ${{ runner.os }}-sonar-scanner
          restore-keys: ${{ runner.os }}-sonar-scanner

so im forcing to run sonarqube installer anyway and removed the line

if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'

so modified looks below and works as the dotnet-sonarscanner is installed and not dependent on Cache SonarQube Cloud scanner

 - name: Install SonarQube Cloud scanner
        shell: powershell
        run: |
          dotnet tool install --global dotnet-sonarscanner --tool-path .\.sonar\scanner
          dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner

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