Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet.exe locking SonarScanner.MSBuild.Common.dll

Good evening,

I am using the .Net Core 2.0 version from here https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild on a 2.1 project in Jenkins with:

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

It works the first build but on the next build it fails with:

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.

and checking my windows server I can see multiple .Net Core Host Background process. If I kill these I can build again..

I readed about msbuild /nodereuse:false for MSBuild but seems is not working for the dotnet core version?

like image 941
Nauzet Avatar asked Dec 17 '22 22:12

Nauzet


2 Answers

We were just faced with this issue, and found out that it's related to dotnet's and msbuild's reuse of nodes that were left running by a previous multi-threaded build.

To avoid the problem, use either /nodereuse:false or /nr:false on your command line as the following:

msbuild /m /nr:false myproject.proj

msbuild /m /nodereuse:false myproject.proj

dotnet restore myproject.sln /nodereuse:false
like image 55
fsteff Avatar answered Dec 26 '22 10:12

fsteff


FYI @Nauzet opened an issue open for this in the Scanner for MSBuild repo: #535.

To summarise:

  • the begin and end steps seem to run fine, and dotnet.exe shuts down as expected for those processes
  • when building a complex solution, multiple instances of dotnet.exe are started and are do not shut down immediately when the build completes. The issue does not seem to occur on simpler solutions.
  • the issue occurs if you trigger the build phase using dotnet build or dotnet msbuild
  • workarounds: build using msbuild directly, or build using dotnet build /nodereuse:false

FYI the Scanner for MSBuild has a couple of custom tasks that are called during the build phase. These use the assembly that is being locked. There's nothing unusual about the custom tasks; they just read data from a file on disk. At this point, I'm not convinced it's an issue with the Scanner for MSBuild.

like image 38
duncanp Avatar answered Dec 26 '22 12:12

duncanp