I've managed to get coverage out of coverlet (https://github.com/tonerdo/coverlet), but so far have been unable to get sonar-scanner for msbuild to finish. some config problem that hopefully I'll sort out soon.
The script I use is:
#!/bin/bash -e
api_key=$API_KEY
# Get nuget packages and then build DEBUG
dotnet restore --packages packages --configfile nuget.config /nowarn:NU1701,NU1603,NU1605 MyApp.sln
# set the version on all the projects
echo Set SDK Versions to [$apiversion]
find sdk -name "*.csproj" -print | xargs -I £ sed -ie "s/<Version>.*<\/Version>/<Version>${apiversion}<\/Version>/g" £
echo Set Implementation Versions to [$version]
find implementation -name "*.csproj" -print | xargs -I £ sed -ie "s/<Version>.*<\/Version>/<Version>${version}<\/Version>/g" £
echo Starting SONAR...
export token=$SONAR_TOKEN
dotnet /bin/SonarScanner.MSBuild.dll begin \
/d:sonar.login=${token} \
/d:sonar.host.url=https://my-sonar-server.com \
/v:$version \
/k:$key \
/d:sonar.analysis.mode=preview \
/d:sonar.cs.opencover.reportsPaths="$(find . -name coverage.xml | tr '\n' ',')" \
/d:sonar.coverage.exclusions=tests/** \
/d:sonar.cs.vstest.reportsPaths="$(pwd)/.output/*.trx" \
/d:sonar.verbose=true
echo Build solution...
dotnet build --no-restore /nowarn:NU1701,NU1603,NU1605 Core.sln /clp:PerformanceSummary
# Run the tests
for testproj in $(ls tests/*.Tests -d); do
echo $testproj;
set +e
time \
dotnet test \
--no-build \
--no-restore \
--filter "TestCategory!=Integration" \
--logger:trx \
-r .output/ \
$testproj \
/nowarn:NU1701,NU1603,NU1605 \
/p:CollectCoverage=true \
/p:CoverletOutputFormat=opencover
set -e
done
dotnet /bin/SonarScanner.MSBuild.dll end /d:sonar.login=$token
You need to reference coverlet in each of your test assemblies.