question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build Solution task fails after SonarQubePre task when using Fakes

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
duncanp-sonarcommented, Aug 17, 2016

@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>
0reactions
duncanp-sonarcommented, Oct 16, 2017

@CodersB reading the responses above, it looks like using the FolderDisambiguator option did work for zmckinnon. Alternatively, you can exclude specific projects from analysis - see https://stackoverflow.com/questions/32563682/how-to-exclude-ignore-referenced-projects-analysis-from-soanrqube

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build Solution task fails after SonarQubePre task when using ...
I am building my solution using the Visual Studio Build task. The task right before it is the SonarQube for MSBuild - Begin...
Read more >
Run Code Analysis task fails on Azure DevOps Server
2.Run build solution task successfully,; Run “Prepare analysis on SonaQube” successfully, here is output. Starting: Prepare analysis on ...
Read more >
MSBuild Fakes Generation failing (SonarQube.Integration ...
This is the error that I get from a solution that generates Fakes assemblies ... then queue build with SonarQube tasks (Build definition:...
Read more >
SonarQube fails to analyse when running CakeBuild on Jenkins
I have a Jenkins job that uses the SonarQube Jenkins plugin for analysis and CakeBuild to build the solution and run the tests....
Read more >
SonarScanner for .NET | SonarQube Docs
The SonarScanner for .NET is the recommended way to launch an analysis for projects/solutions using MSBuild or dotnet command as a build tool....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found