SonarQube Encoding to UTF-8

We have a warning in SonarQube that refers to the file encoding:

WARN: Encoding detected by Roslyn and encoding used by SonarQube do not match for file file://XXXX/XXXX/xxx.cs. SonarQube encoding is 'windows-1252', Roslyn encoding is 'UTF-8'. File will be skipped.

WARN: Invalid character encountered in file/XXXX/XXXX/xxx.cs at line 169 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.

How do we change the encoding in SonarQube to UTF-8?

SonarQube 9.2 is being used.

In Gitlab-ci.yml,we are using below code.

  script: 
      - "apt-get update"
      - "apt-get install --yes openjdk-11-jre"
      - "dotnet tool install --global dotnet-sonarscanner"
      - "export PATH=\"$PATH:$HOME/.dotnet/tools\""
      - "dotnet sonarscanner begin /k:\"platoon\" /d:sonar.sourceEncoding=UTF-8 /d:sonar.login=\"$SONAR_TOKEN\" /d:\"sonar.host.url=$SONAR_HOST_URL\" "
      - "dotnet build"
      - "dotnet sonarscanner end /d:sonar.login=\"$SONAR_TOKEN\""

How to resolve this issue?

Hi,

Encoding defaults to the system encoding. You can override this by explicitly setting sonar.sourceEncoding=UTF-8.

 
HTH,
Ann

@ganncamp Thank you for your suggestion. We updated this setting in the gitlab-ci.yml file, but the warning persists. Is the syntax in gitlab-ci.yml incorrect when we update it?

- "dotnet sonarscanner begin /k:\"platoon\" /d:sonar.sourceEncoding=UTF-8 /d:sonar.login=\"$SONAR_TOKEN\" /d:\"sonar.host.url=$SONAR_HOST_URL\" "

Hi,

I’m a bit out of my depth at this point. I’ve flagged the thread for more expert attention. Hopefully they’ll be along soon.

 
Ann

okay @ganncamp thankyou.

Hello @praseeb_kdas

We’ll need the logs:

  • please give us the verbose output of the scanner commands (please run SonarScanner.MSBuild.exe begin /k:“MyProject” /d:sonar.verbose=true as the begin step, and please attach the output of the BEGIN and END steps)
  • please give the output of running MSBuild in verbose mode ( /v:d )

This topic was automatically closed after 10 days. New replies are no longer allowed.