Package restore fails with Cache error

Topics: General
May 28, 2013 at 12:28 PM
When running package restore on the build server we get the following error every now and then:
.\Solutions\.nuget\nuget.targets(69,5): error : Could not find file 'C:\Users\myUser\AppData\Local\NuGet\Cache\myPackage.5.2.0-a0489279992.nupkg'. [D:\Modules\MyProject\MyProject.csproj]
.\Solutions\.nuget\nuget.targets(69,5): error MSB3073: The command ""..\Solutions\.nuget\nuget.exe" install "D:\Modules\MyProject\packages.config" -source "https://feedserver/Live/api/v2/"   -solutionDir "..\Solutions\ "" exited with code 1.  [D:\Modules\MyProject\MyProject.csproj]
Before this error, a whole bunch of packages were correctly restored.

The package restore is called as follows:
<MSBuild
             Projects="D:\Modules\MyProject\MyProject.csproj"
             Targets="RestorePackages"
             Properties="PackageSources=https://feedserver/Live/api/v2/;RequireRestoreConsent=false"
             ContinueOnError="false" />
The package restore is called like this because we need the dependencies on disk before building to do validations.

We could work around this by adding -NoCache, but that means editing 300+ nuget.targets files.
May 29, 2013 at 8:06 AM
I suspect this is caused by the cache delete happening during the install of the package. There is a max of 200 packages in the cache and we have 200+ unique packages to be pulled in during the build (not counting different versions of the same packages).

At first sight I can't find a mutex around the install/cache clear (having a hard time following the logic of the package install) which could cause the issue.
May 29, 2013 at 8:47 AM
I replaced the package restore call with:
<exec 
           Command="..\.nuget\nuget.exe install &quot;packages.config&quot; -source &quot;https://feedserver/Live/api/v2/&quot; -NoCache -solutionDir &quot;..\ &quot;"
           WorkingDirectory="$(projectfolder)" />
I'm not too happy about this, but if it works as a workaround it will do for now.