Philip Atz
Philip Atz

Reputation: 938

Configuring SonarQube to recognise C# 6.0 syntax

I am setting up our TeamCity build to run a SonarQube analysis of our C# solution. I have already been through one hurdle by using -Dsonar.sourceEncoding=UTF-8 to allow Sonar to recognise the utf-8 BOM header in our files. My current problem has to do with C# 6.0 syntax, like string interpolation, which does not seem to be recognised by Sonar and is giving me "parse errors":

[09:38:39][Step 4/6] 04:38:39.338 ERROR - Unable to parse file: C:\BuildAgent\work\.........\DataLayerTests.cs
[09:38:39][Step 4/6] 04:38:39.338 ERROR - Parse error at line 44 column 46:
[09:38:39][Step 4/6] 
[09:38:39][Step 4/6]    43:             Assert.IsNotNull(results, "The method returned NULL instead of any results.");
[09:38:39][Step 4/6]   -->              Assert.AreEqual(1, results.Count, $"The method returned {results.Count} results instead of 1.");

Is there any additional command line parameter that I need to use with the sonar-runner to ensure compatibility? Or does this have to do with the version of the C# plugin that we use?

I found this other question, which is only tangentially related. That question is about enabling the issues that are spotted by the Roslyn analyser to flow back into SonarQube. My question is a lot more basic than that, as I am not yet even at a stage where Sonar would fully understand my syntax!

Upvotes: 2

Views: 828

Answers (1)

Tamas
Tamas

Reputation: 6420

The C# plugin has been rewritten in version 3.4 to use Roslyn internally. So any later version will handle (parse) C# 6 features. Also, I recommend to update to the latest version as we are constantly adding new rules, and fixing known issues.

You can check the version history here.

Upvotes: 2

Related Questions