MSBuild NuGet.targets ,Nuget.exe : Unable to read package from path 'blah.nupkg' error

自闭症网瘾萝莉.ら 提交于 2019-12-01 15:23:04

I had this same problem using TFS. What I did that fixed it was clear the nuget cache in the user profile that was running the build (%LocalAppData%\NuGet\Cache). I just emptied the directory and ran the build again, then it worked.

If your TeamCity is running under System user account then you can try to clear Nuget Cache which is located in one of these folders:

  • C:\Windows\System32\config\systemprofile\AppData\Local
  • C:\Windows\SysWOW64\config\systemprofile\AppData\Local

In my case, the service account being used to run the build agent had restricted access out to the Internet through our WebSense proxy.

The error message I was getting in the build log:

Unable to read package from path 'EntityFramework.5.0.0.nupkg'.

I navigated to the cache folder for the build agent user (C:\Users\{BuildAgentUser}\AppData\Local\NuGet\Cache) and found the .nupkg file there that was causing the error.

I could see that something was wrong, as the file was only 3KB, when on my own machine it was over 1MB.

Looking at the contents of the .nupkg file revealed the problem - the download had been blocked by WebSense and it actually contained the error message that would have been displayed had it been browsed to in a web browser.

We do this by updating the NuGet config file for the user that the BuildAgent is running under instead of setting a package source and it's worked fine since NuGet v1.6.

File: c\Users\svc_teamcity\AppData\Roaming\NuGet\NuGet.config

Looks like:

<activePackageSource>
  <add key="NuGet official package source" value="https://nuget.org/api/v2/" />
  <add key="MyNuGetGallery" value="D:\NuGet.Packages" />
</activePackageSource>

I had the same problem, but on a mac. What I did was just delete the one nuget package that was causing the problem. It was located at:

/Users/yourusername/.local/share/NuGet/Cache

I know this is an old question, I had faced this issue recently and none of the solution provided above didn't solve my issue. And the reason for the error was, one of the package was corrupted and the .nupkg file size was 0 kb. What I did is the preceding steps, and that solved my issue and I was able to re-install the packages.

  1. Go to your project directory
  2. Open the folder packages
  3. Find the package on which you are getting error (blah.nupkg)
  4. Delete the folder
  5. Build your project and your project will be build successfully
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!