首页 > 解决方案 > dotnet.exe 锁定 SonarScanner.MSBuild.Common.dll

问题描述

晚上好,

我在 Jenkins 的 2.1 项目中使用 .Net Core 2.0 版本https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild :

withSonarQubeEnv('SonarQubeMain') {
    bat "dotnet ${globals.SONAR_QUBE_MSBUILD_PATH}\\SonarScanner.MSBuild.dll begin /k:\"${globals.SONAR_QUBE_PROJECT}\" /d:sonar.host.url=${globals.SONAR_HOST_URL} /d:sonar.cs.xunit.reportsPaths=\"XUnit.xml\" /d:sonar.cs.opencover.reportsPaths=\"coverage.xml\"
}

bat "dotnet build --version-suffix ${env.BUILD_NUMBER}"

dir('test/mytestprojecthere') {
    bat 'D:\\OpenCover\\OpenCover.Console.exe -target:"c:\\Program Files\\dotnet\\dotnet.exe" -targetargs:"xunit --no-build -xml XUnit.xml" -output:coverage.xml -oldStyle -filter:"-[*Tests*]*" -register:user'
}
withSonarQubeEnv('SonarQubeMain') {
    bat "dotnet ${globals.SONAR_QUBE_MSBUILD_PATH}\\SonarScanner.MSBuild.dll end"
}

它在第一次构建时有效,但在下一次构建时失败:

Failed to create an empty directory 'D:\Jenkins\workspace\xxxxxxxx\.sonarqube'. 
Please check that there are no open or read-only files in the directory and that you have the necessary read/write permissions.

Detailed error message: Access to the path 'SonarScanner.MSBuild.Common.dll' is denied.

并检查我的 Windows 服务器,我可以看到多个 .Net Core 主机后台进程。如果我杀了这些,我可以再次建造..

我阅读了有关 MSBuild 的 msbuild/nodereuse:false但似乎不适用于 dotnet 核心版本?

标签: sonarqubesonarqube-scan

解决方案


我们刚刚遇到了这个问题,发现它与 dotnet 和 msbuild 对先前多线程构建留下的节点的重用有关。

为避免此问题,请在命令行中使用/nodereuse:false/nr:false,如下所示:

msbuild /m /nr:false myproject.proj

msbuild /m /nodereuse:false myproject.proj

dotnet restore myproject.sln /nodereuse:false

推荐阅读