Skip to content

Instantly share code, notes, and snippets.

@disouzam
Created December 30, 2022 12:08
Show Gist options
  • Save disouzam/edcb4b981109447711e021c0f937bd0c to your computer and use it in GitHub Desktop.
Save disouzam/edcb4b981109447711e021c0f937bd0c to your computer and use it in GitHub Desktop.
Sample batch script to run SonarScanner locally
@REM In order to execute sonar coverage, you'll need to have sonarqube community downloaded and running local on your machine
@REM and sonarscanner installed as well and placed its /bin folder as a PATH ENVIRONMENT VARIABLE.
@REM Additionaly, you need to provide a Project TOKEN and set its value on LOGIN parameter (line 7).
set project="PLACE PROJECT NAME HERE"
set login="PLACE YOUR TOKEN HERE"
set host=http://localhost:9000
dotnet new tool-manifest --force
dotnet tool update --local dotnet-sonarscanner --version 5.2.1
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
dotnet build-server shutdown
dotnet sonarscanner begin /k:%project% /d:sonar.host.url=%host% /d:sonar.login=%login% /d:sonar.vbnet.opencover.reportsPaths="**\coverage.opencover.xml" /d:sonar.coverage.exclusions="**Tests*.cs,*.json,*.Setup/*.*,*.Repository.*/*.*,**Migrations/*"
dotnet build
dotnet sonarscanner end /d:sonar.login=%login%**
sonar-scanner.bat -Dsonar.scanAllFiles=true -Dproject.settings=.\.sonarqube\out\sonar-project.properties --embedded --debug -Dsonar.login=%login%