1

I am running SonarQube 5.6 version and I am trying to integrate .NET application with Sonar. After running sonar-runner, I am getting this warning message

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

This is resulting in 0 analysis as all files are getting skipped. One way to make it work is by changing .cs file encoding from Visual Studio one-by-one to windows-1252. This is not feasible as I have big projects with over 1000 files.

Is there any way we can change the encoding for SonarQube? or is there any other way to resolve this.

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
Kshitiz
  • 11
  • 2
  • We have the same issue. Is there a way to set a different encoding for SonarQube or Roslyn so they are in sync? It is preventing our project from generating any meaningful analysis result so it is a show-stopper to us. – pumpump Dec 14 '17 at 02:50

1 Answers1

0

It's not possible currently to change the encoding. However, you can easily change the encoding of all your files by following the suggestion here: https://stackoverflow.com/a/850751/1410281

foreach (var f in new DirectoryInfo(@"...").GetFiles("*.cs", SearchOption.AllDirectories)) {
  string s = File.ReadAllText(f.FullName);
  File.WriteAllText (f.FullName, s, Encoding.UTF8);
}
Community
  • 1
  • 1
Tamas
  • 6,260
  • 19
  • 30
  • Thats a work around but it may get some issues in TFS while file compare or merge. Not sure of this. Ideally there has to be a way to change SonarQube encoding for a project. – Kshitiz Feb 13 '17 at 11:27
  • You're right, there should be a way, and I'm sure that SonarSource is working on this issue (see `DEFAULT-PROJECT-ENCODING` branch in [Scanner for MsBuild](https://github.com/SonarSource-VisualStudio/sonar-scanner-msbuild)), but right now UTF-8 is hardcoded. – Tamas Feb 13 '17 at 12:03