9
votes

We're using TeamCity (9.0) as our CI server to build, test and deploy several applications. Recently we are seeing occassional (one in every 30/40 builds or so) NuGet (2.8.3) errors 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 being used by another process.

where the actual package seems to differ from time to time.

We suspected it has something to do with the same package being referenced in multiple projects within the same solution, but I would expect NuGet to be able to handle this correctly by filtering out duplicates instead of attempting to retrieve the same package multiple times, thereby ending up with write-locks when restoring the packages to the work folder.

As a first step of each Build Configuration we have a 'NuGet Installer' step set to 'restore'. I've tried fiddling with its settings (different 'Update modes', '-NoCache', older NuGet version (2.8.0)), but to no avail.

Has anyone else experienced similar issues, and if so, has any suggestions on how to ensure this error does not occur.

Any help would be greatly appreciated!

5
after trying everything below, was this ever resolved for you?workabyte
Sorry, a little late to reply. None of the suggestions below seemed to work for us unfortunately. I'm not sure what eventually fixed the issue, but it seems to have stopped at some point. If anything I'm guessing a newer version of NuGet may have solved the issue, but I haven't been able to confirm that fully.Jiri

5 Answers

10
votes

I had the same issue with Jenkins and fixed that by adding "-DisableParallelProcessing" to the nuget restore command, the final command would look like:

nuget restore "%WORKSPACE%\Solutions\App\App.sln" -DisableParallelProcessing
3
votes

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

I used the SysInternals Process Explorer utility on the build agents to search for file handles for any *.nupkg files while the builds were running. After several builds I observed the anti-malware products briefly locking these files during the NuGet restore operations. Adding an exclusion to the anti-malware scanning rules prevented these locks as the files were no longer being scanned.

In our environment we use two different anti-malware products on different build agent servers. We encountered this issue with both products.

0
votes

As far as the error message is concerned, I also came across it.

I debugged the “nuget restore” process, breaking at the point where the .nupkg is copied to the local repository, and then freezing the thread while the file was opened for writing. And sure enough I got the exception in another task, due to the fact that the two packages had Ids where one was a prefix of the other. I filed an issue for this : https://nuget.codeplex.com/workitem/4465.

However, this is probably not exactly your problem, since the error in my case is on reading the .nupkg of the package with the “long” name, and I don’t think there is a package with an Id that is a prefix of NewtonSoft.Json (whereas it is very possible the other way around : there are for instance NewtonSoft.JsonResult of NewtonSoft.Json.Glimpse).

0
votes

I installed new Newtonsoft.Json and problem disappear

-1
votes

You can turn on build feature Swabra with option "Locking processes" (requires handle.exe). And check are there any files locked after build's finish or not. If there are no locked files then try to run Nuget using command line build step instead of NuGet Installer. If the issue is reproduced then most probably it means that the issue is related NuGet.