File access issue during Nuget Install step

We have builds on NuGet Enterprise 9.0.1 that are failing intermittently during a NuGet Install step with an error of the form:

The process cannot access the file 'C:\BuildAgent\work\{workdir}\packages\{nuget pkg name}\{nuget pkg name}.nupkg' because it is being used by another process.

In each case the offending package is a dependency of multiple projects in the solution. We currently have 6 agents in our environment, however this error occurs even when no other builds are running simultaneously. Our current workaround is to rerun the build, but in general these builds seem to fail around 20% of the time with this error.

How can I resolve this issue?

Comment actions Permalink

Hi Adam,

Could you please turn on build feature Swabra and turn on option "Locking processes" (requires handle.exe)? And check are there any files locked after build finish or not.
If there are no locked files then please 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 not related to TeamCity.
Also please specify which NuGet version you use.

Comment actions Permalink

Thanks Alina. We are currently using NuGet 2.8.3.

I've added the Swabra build feature. It consistently reports that "No processes found locking files" after each build.

I've tried using the NuGet command line installer, but the errors continue.

Any other suggestions?

Comment actions Permalink

Please try to find which process locked this file, you can use Handle utility.

Comment actions Permalink

Using Process Explorer I found that on some agents in our environment MsMpEng.exe was locking the file, and on other agents the System process was locking the file.

In both of these cases the culprit was an anti-malware product that briefly opened a handle on the *.nupkg files during the NuGet restore. Adding an exclusion rule for these packages and locations to the appropriate product resolved the issue.

Swabra didn't report these locks because they were released before the Swabra build step ran.

Thanks again for your help!


Please sign in to leave a comment.