azure-pipelines-tasks: Build Solution task fails after SonarQubePre task when using Fakes

I am building my solution using the Visual Studio Build task.

The task right before it is the SonarQube for MSBuild - Begin Analysis.

I am using Microsoft Fakes with my project.

Sometimes (like every other time or so), I get the following error when building:

Error MSB3231: Unable to remove directory "F:\Agent-03\_work\1\.sonarqube\out\\f_AnyCPU_Release_4391". The process cannot access the file 'FilesToAnalyze.txt' because it is being used by another process.

Here are the logs: logs_40521.zip

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 23 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@zmckinnon no, I’m afraid not. A tool like SysInternals Process Monitor might help pin it down.

Here’s a possible workaround: copy the following XML into a file (the name doesn’t matter) and dump it on the agent machine. The detailed explanation is in the file: the short version is that it attempts to guarantee that the per-project folder name is unique by using a guid.

You’ll be able to tell if the file is being used by looking for the text “FolderDisambiguator” in the build output.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <!-- This target changes the suffix used to disambiguate folders names.
       It's an attempt to work round a problem encountered when generating fakes -
         the build is failing because the integration targets are attempting
         to delete a folder that contains a locked file. However, the folder names
         are supposed to be unique to the project, and include a tick/timestamp suffix.

         This tweak uses a GUID instead which should definitely be unique, at the cost of
         increasing the length of the name i.e. there is the possibility that the generated
         name will be too long.

         USAGE: drop this file in the standard MSBuild ImportBefore folder for the version
           of MSBuild you are using (create the ImportBefore folder if it does not exist)
           e.g. %ProgramFiles(x86)%\msbuild\14.0\Microsoft.Common.Targets\ImportBefore
  -->

  <PropertyGroup>
    <FolderDisambiguator Condition=" $(FolderDisambiguator)=='' ">_$(Platform)_$(Configuration)_$([System.Guid]::NewGuid().ToString())</FolderDisambiguator>
  </PropertyGroup>

  <!-- This target is not required: it simply writes out additional information to simplify debugging -->
  <Target Name="ChangeFolderDisambiguator_DEBUG" BeforeTargets="CoreCompile"
          Condition=" $(SonarQubeTempPath) != '' ">
    <Message Importance="high" Text="FolderDisambiguator = $(FolderDisambiguator)" />
  </Target>

</Project>