我已设法在.NET
泊坞广告容器上使用SonarQube Scanner for MSBuild对debian:stretch
核心项目执行静态代码分析。
我现在正在尝试制作一份报道报道。
除非我错了,否则相关guidelines暗示您不能只使用现有报告,而是遵循动态流程
begin
通过指向报告(待完成)路径a)Visual Studio代码覆盖率
b)dotCover
c)OpenCover
end
msbuild
我的问题是,是否可以在Linux上运行上述过程(尚未设法这样做或找到任何资源)
答案 0 :(得分:1)
我设法从封面(https://github.com/tonerdo/coverlet)获得了覆盖范围,但到目前为止还无法让msbuild的声纳扫描程序完成。一些配置问题,希望我很快就会解决。
我使用的脚本是:
#!/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
您需要在每个测试装配中引用封面。
答案 1 :(得分:1)
覆盖率报告以及 SonarQube集成可能超过minicover。
Minicover现在使用mini-OpenCover生成(并上传到SQ服务器)与SQ兼容的覆盖报告; 应该遵循的程序或多或少,脚本化:
(假设tools
是执行minicover的块安装的文件夹)
echo "Starting sonarqube integration"
mono /home/pathTo/SonarQube.Scanner.MSBuild.exe begin /k:"MyProject" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="myLoginId" /d:sonar.cs.opencover.reportsPaths="coverage.xml"
dotnet restore
dotnet build
cd tools
export "MiniCover=dotnet minicover"
# Instrument assemblies inside 'MyTestFolder' folder to detect hits for source files inside 'MySrcFolder' folder
$MiniCover instrument --workdir ../ --assemblies MyTestFolder/**/bin/**/*.dll --sources MySrcFolder/**/*.cs
# Reset hits count in case minicover was run for this project
$MiniCover reset
cd ..
dotnet test --no-build ./MyTestFolder/MyTest.csproj
cd tools
# Uninstrument assemblies, it's important if you're going to publish or deploy build outputs
$MiniCover uninstrument --workdir ../
# Create html reports inside folder coverage-html
$MiniCover opencoverreport --workdir ../ --threshold 90
# Print opencover report
$MiniCover opencoverreport --workdir ../ --threshold 90
cd ..
echo "Ending sonarqube integration..."
mono /home/pathTo/SonarQube.Scanner.MSBuild.exe end /d:sonar.login="myLoginId"