NuGet error in TeamCity: the process cannot access the file because it is being used by another process

We use TeamCity (9.0) as our CI server to create, test, and deploy multiple applications. Recently, we have been observing random (one for every 30/40 bit) NuGet errors (2.8.3) as follows:

[restore] The process cannot access the file C: \ BuildAgent \ work \ e32cbd0940f38bf ..... \ packages \ Newtonsoft.Json.5.0.6 \ Newtonsoft.Json.5.0.6.nupkg 'because it is used by another process.

where the actual package seems to be different from time to time.

We suspected that this was due to the fact that the same package refers to several projects within the same solution, but I expect NuGet to be able to handle this correctly by filtering out duplicates instead of trying to get the same one the same package several times, thereby ending with the recording of locks when restoring packages in the working folder.

As the first step of each build configuration, we have NuGet Installer installed for recovery. I tried to mess with my settings (different "Update Modes", "-NoCache", an older version of NuGet (2.8.0)), but to no avail.

Has anyone else encountered similar problems, and if so, then there are suggestions on how to ensure that this error does not occur.

Any help would be greatly appreciated!

+8
nuget teamcity
source share
5 answers

I had the same problem with Jenkins and fixed that adding nuget "-DisableParallelProcessing" to the recovery command, the last command would look like this:

nuget restore "%WORKSPACE%\Solutions\App\App.sln" -DisableParallelProcessing 
+9
source share

Exclusion of NuGet package files from our anti-malware products resolved this issue for us.

I used the SysInternals Process Explorer utility for assembly agents to search for files for any * .nupkg files while the assembly was running. After several builds, I noticed that anti-malware products lock these files momentarily during NuGet recovery operations. Adding an exception to the anti-virus scan rules prevented these locks because the files were no longer scanned.

In our environment, we use two different antivirus products on different build agent servers. We ran into this problem with both products.

+2
source share

As for the error message, I also ran into it.

I debugged the "nuget" recovery process, breaking up at the point where .nupkg is being copied to the local repository, and then freezes the stream while the file is open for writing. And, of course, I got an exception in the other task, because the two packages had identifiers in which one was the prefix of the other. I wrote a question for this: https://nuget.codeplex.com/workitem/4465 .

However, this is probably not exactly your problem, since the error in my case is reading the .nupkg package with the "long" name, and I donโ€™t think there is a package with an identifier that is a prefix from NewtonSoft.Json (whereas this it is very possible the opposite: there is, for example, NewtonSoft.JsonResult from NewtonSoft.Json.Glimpse).

0
source share

I installed new Newtonsoft.Json and the problem disappeared

0
source share

You can enable the Swabra build function with the Process Lock option (handle.exe is required). And check if any files are locked after the build is complete or not. If there are no locked files, try starting Nuget using the command line step instead of NuGet Installer. If the problem reproduces, then most likely it means that the problem is related to NuGet.

-2
source share

All Articles