Sonarqube dotnet.exe.MSBuild.Common.dll

Sonarqube dotnet.exe.MSBuild.Common.dll,sonarqube,sonarqube-scan,Sonarqube,Sonarqube Scan,晚上好, 我正在Jenkins的2.1项目中使用.Net Core 2.0版本,其中包括: 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:s

晚上好,

我正在Jenkins的2.1项目中使用.Net Core 2.0版本,其中包括:

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核心主机的后台进程。如果我杀了这些我可以再造一次


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

请按如下所示编辑管道脚本,它应该可以正常工作:

    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'
}

bat "dotnet ${globals.SONAR_QUBE_MSBUILD_PATH}\\SonarScanner.MSBuild.dll end"
    }
更新

下面是我使用的dotnet核心应用程序管道构建脚本,它运行良好,没有任何问题:

bat "dotnet ${sqScannerMsBuildHome}\\SonarScanner.MSBuild.dll begin /k:yoursonarprojectkey /n:yoursonarprojectname /v:1.0 /d:sonar.host.url=%SONAR_HOST_URL%"
bat 'dotnet build'
bat "dotnet ${sqScannerMsBuildHome}\\SonarScanner.MSBuild.dll end"

我只是自己遇到了这个问题,并通过运行
dotnet构建服务器关机
作为构建计划中的第一个任务来“解决”它。由于多种原因,这并不理想,其中一个主要原因是,如果我试图在同一台机器上同时运行多个.NET核心构建,可能会导致问题。这似乎是扫描仪中的一个bug,希望很快就能修复。

FYI@Nauzet在MSBuild repo的扫描仪中为此打开了一个问题:

总结如下:

  • 开始和结束步骤似乎运行正常,dotnet.exe会按预期关闭这些进程
  • 构建复杂解决方案时,会启动dotnet.exe的多个实例,但不会在构建完成后立即关闭。这个问题似乎不会发生在更简单的解决方案上
  • 如果使用dotnet build或dotnet msbuild触发生成阶段,则会发生此问题
  • 解决方法:直接使用msbuild生成,或使用dotnet build/nodereuse生成:false

仅供参考,MSBuild的扫描程序有两个自定义任务,这些任务在生成阶段调用。它们使用要锁定的部件。定制任务没有什么不寻常的地方;他们只是从磁盘上的文件中读取数据。在这一点上,我不认为MSBuild的扫描程序有问题。

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

要避免此问题,请在命令行上使用
/noderereuse:false
/nr:false
,如下所示:

msbuild /m /nr:false myproject.proj

msbuild /m /nodereuse:false myproject.proj

dotnet restore myproject.sln /nodereuse:false

我遇到了同样的问题,运行下面的命令解决了这个问题

dotnet build-server shutdown
这是由于重新使用msbuild节点造成的。我们让msbuild节点保持活动状态,目的是在执行连续生成时节省启动时间

它也可以通过设置以下环境变量来关闭

MSBUILDDISABLENODEREUSE=1

也不行。但是我花了几个小时尝试了一些东西,我可以肯定地说问题是由运行扫描仪后的
dotnet build
引起的。我想是因为我的版本是.NETCore2.1,所以我会等待更新。无论如何,文件似乎在几分钟后被解锁。因为这是我的家庭实验室,我是唯一一个使用jenkins的人,所以我现在可以在管道的末尾这样做:
bat“taskkill/FI\”MODULES eq sonascanner.MSBuild.Common.dll\“/FI\”USERNAME eq jenkins\“/F”
但这显然是可行的,因为meI的dotnet核心应用程序在同一时间只有一个版本,我运行它时没有任何问题,所以它肯定不是dotnet版本。你能拿出打开的封面部分,只做应用程序编译和查看吗?这就是我所拥有的,它没有任何问题。你的项目是什么样的?任何后期构建或预构建步骤?我已经添加了管道脚本。请检查我在没有opencover的情况下测试了它,没有单元测试,在不同的机器上运行,从解决方案中删除了项目。。我的解决方案有:library1(netstandard2.0)library2(netstandard2.0,对library1的依赖)consoleApp1(netcoreapp2.1对library2的依赖)consoleApp2(netcoreapp2.1对library2的依赖)UnitTests(netcoreapp2.1对library2)我删除了所有内容,但library1->正确构建不锁定。添加的library2->dotnet build会将sonarscanner DLL锁定数分钟。