NuGet:程序包'Microsoft.AspNet.WebApi.Client.5.2.3'已存在于文件夹安装失败。滚回来

时间:2017-03-23 23:00:39

标签: asp.net visual-studio visual-studio-2015 nuget nuget-package

我已经格式化了我的PC并从git repo克隆了我(之前正在工作的)项目。

我尝试重新安装软件包:

PM> update-package -reinstall

它尝试安装许多软件包,但在Microsoft.AspNet.WebApi.Client.5.2.3

时出错
Package 'Microsoft.AspNet.WebApi.Client.5.2.3' already exists in folder 'C:\Users\can\Source\Repos\MyProject\MyProject\packages'
Install failed. Rolling back...
Package 'Microsoft.AspNet.WebApi.Client 5.2.3' does not exist in project 'Web'

然后执行更多命令后,我得到:

update-package : Failed to add reference to 'System.Net.Http'. Please make sure that it is in the Global Assembly Cache.
At line:1 char:1
+ update-package -reinstall
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Update-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand

我尝试删除本地缓存但无济于事。我已经在Visual Studio(管理NuGet包)中更新了GUI中的所有包。如果我尝试构建我的解决方案,我会在两个项目中得到这个(并且解决方案无法构建):

This project references NuGet package(s) that are missing on this computer.
Use NuGet Package Restore to download them.
For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.
The missing file is ..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets.

我在做什么呢?

1 个答案:

答案 0 :(得分:2)

  

如果我尝试构建我的解决方案,我会在两个项目中得到这个(并且解决方案无法构建)

这是因为Microsoft.Bcl.Build.1.0.21的相对路径不正确,需要编辑.csproj文件并更正相对路径。或者从.csproj文件中删除以下代码

  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
  <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />

然后update-package -reinstall

此外,重新安装错误:

确保恢复所有包。然后使用命令update-package -reinstall -Project projectname为解决方案中的每个项目重新安装软件包。