How to setup SonarScanner for .NET Framework in AWS Code Build?

Hello! I’m using AWS CodeCommit and AWS CodeBuild to use Sonar in my .NET Framework Application. I created the following buildspec file:

version: 0.2

phases:
  install:
    runtime-versions:
      java: corretto11
      dotnet: 3.1
    commands:
      - Invoke-WebRequest -Uri https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/5.11.0.60783/sonar-scanner-msbuild-5.11.0.60783-net46.zip -OutFile sonar-scanner.zip
      - Expand-Archive sonar-scanner.zip -DestinationPath C:\sonar-scanner
  build:
    commands:
      - setx /M PATH "%PATH%;C:\sonnar-scanner"
      - refreshenv
      - SonarScanner.MSBuild.exe begin /k:$PROJECTKEY /d:sonar.organization=SONARCLOUD_ORG /d:sonar.login=$SONARCLOUD_TOKEN /d:sonar.exclusions=**/scripts/** /d:sonar.host.url=https://sonarcloud.io
      - MsBuild.exe /t:Rebuild
      - SonarScanner.MSBuild.exe end /d:sonar.login=$SONARCLOUD_TOKEN
  post_build:
    commands:
      - echo Building Project
      - echo Finished Building

The image is a Windows Server but whenever I run I get this error:

SonarScanner.MSBuild.exe : The term ‘SonarScanner.MSBuild.exe’ is not
56 recognized as the name of a cmdlet, function, script file, or operable
57 program. Check the spelling of the name, or if a path was included, verify
58 that the path is correct and try again.

I tried to remove refreshenv, remove the /m argument, change the PATH and use the full path but any of these solved my problem. Anyone know what can I do ?

Hi,

Welcome to the community!

Per the docs did you

  • Add $install_directory to your PATH environment variable.

?

 
Ann