Hi all! I am running static analysis using the .Net SonarScanner (SonarScanner.MSBuild.exe)
I am able to run a successful .net scan when I supply only a single /d parameter (sonar.branch.name) via command line:
“C:\SonarScanner\SonarScanner.MSBuild.exe” begin /k:“MySonarProject” /d:sonar.branch.name=refs/heads/master
The problem is, I don’t know how to supply multiple parameters. Specifically, I want to provide a path to the OpenCover report xml file (via sonar.cs.opencover.reportsPaths setting). What is the correct syntax for supplying multiple different settings via command line? I tried semicolon separating the settings supplied after the /d with no success:
“C:\SonarScanner\SonarScanner.MSBuild.exe” begin /k:“MySonarProject” /d:sonar.branch.name=refs/heads/master;sonar.cs.opencover.reportsPaths=“Path to opencover report xml file”
I appreciate any guidance on how to tell sonarscanner where my opencover report is.
Welcome to SonarSource community and Happy New Year.
The correct syntax is the following:
“C:\SonarScanner\SonarScanner.MSBuild.exe” begin /k:“MySonarProject” /d:"sonar.branch.name=<branchName>" /d:"sonar.cs.opencover.reportsPaths=<pathToOpenCoverReport>" /d:"<anotherProperty>=<anotherValue>"
You can add as many properties as needed with successive /d (or -d) settings
Note that the sonar.branch.name property:
– Should not be set if the branch you are analysing is the main branch (which master typically is)
– Should beset without any refs prefix when you analyze another branch (eg sonar.branch.name=release-1.0 or sonar.branch.name=feature/foo
Note also that it’s good practice to double quote the /d:"<propertyName>=<propertyValue>" to protect yourself from mis-interpretation of whitespace in values or paths that can be in those properties
Thank you for helping me with this issue. Your advice was all very useful to me, and your point about having a /d for each successive setting was the key to fixing my problem. It all just works now!
Perhaps other people could benefit from having this explicitly mentioned in the docs? It may be mentioned there and I just missed it though.