Error MSB4018: The "MoveDirectory" task failed unexpectedly. System.IO.IOException: Cannot create a file when that file already exists

Azure DevOps Server 2020 Update 1.1
SonarQube Extension version 4.23.1
SonarScanner for MSBuild version 5.3.1

SonarQube.Integration.targets fails at line 418 with the following error log:

    61>RazorCoreCompile:
         CompilerServer: server - server processed compilation - 3686d2c2-a462-4e2f-921c-ae4f43f83712
    58>SonarWriteFilesToAnalyze:
         Sonar: (Enscape.Localization.csproj) Number of files to analyse: 104. The list of files to be analyzed is in C:\tfs\Agent\_work\3\.sonarqube\conf\225\FilesToAnalyze.txt.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.Directory.InternalMove(String sourceDirName, String destDirName, Boolean checkHost)
   at SonarScanner.MSBuild.Tasks.MoveDirectory.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
    61>C:\tfs\Agent\_work\3\.sonarqube\bin\targets\SonarQube.Integration.targets(418,5): error MSB4018: The "MoveDirectory" task failed unexpectedly. [C:\tfs\Agent\_work\3\s\Source\WebServices\Template\Enscape.Template\Enscape.Template.csproj]
C:\tfs\Agent\_work\3\.sonarqube\bin\targets\SonarQube.Integration.targets(418,5): error MSB4018: System.IO.IOException: Cannot create a file when that file already exists. [C:\tfs\Agent\_work\3\s\Source\WebServices\Template\Enscape.Template\Enscape.Template.csproj]
C:\tfs\Agent\_work\3\.sonarqube\bin\targets\SonarQube.Integration.targets(418,5): error MSB4018:  [C:\tfs\Agent\_work\3\s\Source\WebServices\Template\Enscape.Template\Enscape.Template.csproj]
C:\tfs\Agent\_work\3\.sonarqube\bin\targets\SonarQube.Integration.targets(418,5): error MSB4018:    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) [C:\tfs\Agent\_work\3\s\Source\WebServices\Template\Enscape.Template\Enscape.Template.csproj]
C:\tfs\Agent\_work\3\.sonarqube\bin\targets\SonarQube.Integration.targets(418,5): error MSB4018:    at System.IO.Directory.InternalMove(String sourceDirName, String destDirName, Boolean checkHost) [C:\tfs\Agent\_work\3\s\Source\WebServices\Template\Enscape.Template\Enscape.Template.csproj]
C:\tfs\Agent\_work\3\.sonarqube\bin\targets\SonarQube.Integration.targets(418,5): error MSB4018:    at SonarScanner.MSBuild.Tasks.MoveDirectory.Execute() [C:\tfs\Agent\_work\3\s\Source\WebServices\Template\Enscape.Template\Enscape.Template.csproj]
C:\tfs\Agent\_work\3\.sonarqube\bin\targets\SonarQube.Integration.targets(418,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\tfs\Agent\_work\3\s\Source\WebServices\Template\Enscape.Template\Enscape.Template.csproj]
C:\tfs\Agent\_work\3\.sonarqube\bin\targets\SonarQube.Integration.targets(418,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\tfs\Agent\_work\3\s\Source\WebServices\Template\Enscape.Template\Enscape.Template.csproj]
    61>Done Building Project "C:\tfs\Agent\_work\3\s\Source\WebServices\Template\Enscape.Template\Enscape.Template.csproj" (default targets) -- FAILED.

This fails unreliably on different machines (build agents) every once in a while.

Hi @timokopf,

Would you like to share the full analysis logs so that we can understand better the issue?

Best regards,
Fan

Also @timokopf, could you provide a bit more info about your setup:

  • are you using self-hosted build agents?
  • are you do you have multiple agents installed on the same physical box?

@Fan_Yang ,
what do you mean by “full analysis log”? Do you mean the build log?

@duncanp,
we use self-hosted agents. No, every agent is a separate machine.

Hi @timokopf,

The full build log will be fine.

BR,
Fan

Hello @Fan_Yang

buildlog_part1.txt (3.3 MB)
buildlog_part2.txt (3.5 MB)

I have attached the full build log separated into two files because of the file size limit.

Best Regards,
Timo

Hi @timokopf ,

I would like to ask for full sonarqube analysis logs as well.

@timokopf the errors in the logs relate to processing Razor files. However, there isn’t enough information in the logs to be more specific than that.

Could you supply verbose logs for the MSBuild step please? (pass /v:diag as an additional argument to MSBuild). Thanks.