SonarCloud for C# Framework Project

Hello :slight_smile:

We have a project that contains two parts. A VScode Client in Typescript and a LSP Server in C# Framework.
We would like to get it analysed by SonarCloud.
This works: Client code gets uploaded to SonarCloud and gets analyzed. Works perfectly.
The Problem: our server code gets also uploaded but sonar does not analyse it. Indeed it kinda thinks its Java. There are also some deep neasted Java files in our project and those gehts analysed. But we don’t want that, we would like to have our c# files analyzed.
We tried to set some config files from java to cs but that does not work.

How can we tell sonar the right way it should analyse our c# code instand of java?

Thank you very much for your help!

Link SonarCloud: https://sonarcloud.io/code?id=dafny-server

GitLab Sonar part in our docker build:

Summary

ARG SonarScanner_RELEASE=3.0.3.778

RUN curl -o sonarscanner.zip -L https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-{SonarScanner_RELEASE}-linux.zip && \ unzip sonarscanner.zip && \ rm sonarscanner.zip && \ mv sonar-scanner-{SonarScanner_RELEASE}-linux sonar-scanner
ENV PATH=$PATH:/opt/sonar-scanner/bin

ENV SONAR_RUNNER_HOME=/opt/sonar-scanner

GitLab sonar-project.properties

Summary

sonar.host.url=https://sonarcloud.io
sonar.organization=hsr
sonar.projectKey=dafny-server
sonar.projectName=Dafny Server
sonar.projectVersion=1.0

client und server trennen

sonar.modules=clientplugin-module, server-module

client teil für TS

clientplugin-module.sonar.projectName=Client Plugin
clientplugin-module.sonar.projectBaseDir=VSCodePlugin
clientplugin-module.sonar.sources=src
clientplugin-module.sonar.tests=test
clientplugin-module.sonar.language=ts
clientplugin-module.sonar.ts.tslint.path=node_modules/.bin/tslint

server teil für C#

server-module.sonar.language=cs
server-module.sonar.projectName=LSP Server
server-module.sonar.projectBaseDir=dafny
server-module.sonar.sources=Source
server-module.sonar.binaries=Binaries
server-module.sonar.tests=Test
server-module.sonar.dotnet.visualstudio.solution.file=Dafny.sln
server-module.sonar.java.binaries = Binaries

GitLab Yaml:

Summary

variables:
BUILD_IMAGE: $CI_REGISTRY_IMAGE/dafny-linux-mono-build
NUnitRunner: NUnit.ConsoleRunner.3.10.0/tools/nunit3-console.exe
NUnitNugetPackage: nunit.consolerunner

stages:

  • prebuild
  • build
  • test
  • sonar

cache:
key: ${CI_COMMIT_REF_SLUG}
paths:

  • VSCodePlugin/node_modules/

build_image:
stage: prebuild
image: docker:latest
only:
refs:
- master
changes:
- Dockerfile.build
- .gitlab-ci.yml
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build --tag $BUILD_IMAGE:latest - < Dockerfile.build
- docker push $BUILD_IMAGE:latest

build_dafny:
stage: build
image: $BUILD_IMAGE:latest
script:
- if [ ! -e boogie ];
then ln -s /opt/boogie;
fi;
- cd dafny/Source
- nuget restore Dafny.sln
- msbuild Dafny.sln
artifacts:
paths:
- dafny/Binaries/

sonar_test:
stage: sonar
image: $BUILD_IMAGE:latest
only:
- master@dafny-sa/dafny-server-redesign
script:
- sonar-scanner

build_vscode_extension:
stage: build
image: $BUILD_IMAGE:latest
script:
- cd VSCodePlugin
- npm install
- npm run vscode:prepublish
artifacts:
paths:
- VSCodePlugin/out/

test_nunit:
stage: test
image: $BUILD_IMAGE:latest
script:
- pushd dafny/Binaries; ln -s /opt/z3; popd
- cd dafny/Binaries/
- nuget install nunit.consolerunner
- mono ./$NUnitRunner FileHelperTests.dll
- mono ./$NUnitRunner CompletionHandlerTest.dll
- mono ./$NUnitRunner VerificationServiceTest.dll
- mono ./$NUnitRunner CompileHandlerTest.dll
- mono ./$NUnitRunner CounterExampleTest.dll
artifacts:
reports:
junit: dafny/Binaries/TestResult.xml

test_vscode_xvfb:
stage: test
image: $BUILD_IMAGE:latest
script:
- |
Xvfb :99 -ac -screen 0 XVFB_WHD -nolisten tcp 2>&1 | grep -v "_XSERVTransmkdir: ERROR: euid != 0,directory /tmp/.X11-unix will not be created." & xvfb=!
for i in (seq 1 10); do echo "Waiting for Xvfb..." sleep 1 xdpyinfo -display {DISPLAY} >/dev/null 2>&1
if [ $? -eq 0 ]; then break; fi
if [ “$i” -gt 9 ]; then echo “Waiting for Xvfb timed out. (Waited for $i seconds)”; exit 255; fi
done
- cd VSCodePlugin
- npm install
- npm run test

test_dafny:
stage: test
image: $BUILD_IMAGE:latest
script:
- cd dafny
- pushd Binaries; ln -s /opt/z3; popd
- npm install bignumber.js #TODO: Should this be global or in build dependency? Else package.json with fixed versions!
- cd Test
- “find . -name ‘.dfy’ -not -path './compileHandlerFiles/’ -not -path ‘./CounterExampleFiles/*’ -exec sed -i ‘s!/optimize !!g’ {} +”
- lit --time-tests -v .

Hi @justme and welcome to the community !

The C# code base can only be analysed with the Scanner for MSBuild, it won’t fail with the standard scanner, but no issues will be raised on SonarCloud.

That being said, you will have to create 2 different projects on SonarCloud, and analyze you codebase twice (one for the java/js codebase, one for C#) in order to get proper analysis result.

Thank you.

Mickaël

1 Like

A post was split to a new topic: Analysing C# in the cloud