This error occurs sometimes, usually this step works fine, but in about 10% cases it fails with below message.
Nuget installer step is first build step, and also "clean checkout" is enabled in TeamCity, so there shouldn't be any process that uses file.
[restore] The process cannot access the file 'C:\BuildAgent\work...\packages\Microsoft.Bcl.Build.1.0.21\Microsoft.Bcl.Build.1.0.21.nupkg' because it is being used by another process.
[restore] Process exited with code 1
Root cause of "my file is being used by another process"
There are several things you can do, depending on what is the root cause:
You use parallel build feature of MSBuild: According to his blog, It seems to not work well with NuGet package restore, because it could runs parallel package restore for each projects (and if several projects require Microsoft.Bcl.Build... Boom!). Either disable parallel build or do package restore outside of solution (in a command line step). By the way, it's not a good practice to do NuGet restore with solution MSBuild.
There is another process:
Use process monitor/explorer to find
out which process hold the lock on the file. It could be an antivirus, file indexing tool, an additional build agent instance which keep running in the background. As the lock is not permanent, and 1 out of 10 is quite a lot for this kind of issue, I would not bet that this is the root cause.
There is no other process:
It's a bug in the Teamcity NuGet installer which do something. Then you could replace the step by a command line step with a call to nuget restore
and check if it fixes your problem.
Diagnose yourself with a nuget plugin of your flavor:
NuGet plugin code is available here. It means you can compile a version of your own, with additional debugging information when these kind of problem happen (list of process locking the file for example). Or even more useful, you can add a retry step in case the file is locked.
EDIT: For those who use Teamcity on Unix...
I've tried to install Teamcity on Unix and make a build on mono with the NuGet plugin. By the way, NuGet plugin does not work at all on Unix (It's not supported by JetBrains). I even tried to fix it but it was easier to just replace it with a command line.
Do you have separate working directory for each build agent? Otherwise two paralel builds could execute in the same time.
Try this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With