该项目引用了此计算机上缺少的NuGet软件包

在尝试构建ASP.NET MVC5应用时遇到'该项目引用了此计算机上缺少的NuGet软件包'的错误。已尝试自动下载、删除并重新下载包,以及检查更新,但问题仍然存在。解决方案包括检查csproj文件中的路径、删除不再需要的MSBuild集成恢复设置、安装特定的软件包、确保项目间NuGet包版本一致,以及更新Microsoft.Build.Bcl版本。
摘要由CSDN通过智能技术生成

本文翻译自:This project references NuGet package(s) that are missing on this computer

I have an ASP.NET MVC5 application that worked yesterday and now I am getting this error when I try to build: 我有一个昨天运行的ASP.NET MVC5应用程序,现在尝试构建时出现此错误:

This project references NuGet package(s) that are missing on this computer. 该项目引用了此计算机上缺少的NuGet软件包。

I have the two options checked that allow nuget to automatically download and install missing packages checked / turned ON. 我选中了两个选项,它们允许nuget自动下载并安装已选中/已打开的缺少软件包。 I have also tried deleting all of the files in the packages folder and then have nuget re-download them. 我还尝试删除了packages文件夹中的所有文件,然后让nuget重新下载它们。 Also when I open nuget and look for updates it says there are none that need to be installed. 另外,当我打开nuget并查找更新时,它说没有安装任何内容。 I can't figure what else to do to move beyond this amazingly annoying issue. 我想不出什么其他办法来解决这个令人讨厌的问题。


#1楼

参考:https://stackoom.com/question/1y7Oa/该项目引用了此计算机上缺少的NuGet软件包


#2楼

Is it possible that the packages have been restored to the wrong folder? 软件包是否可能已还原到错误的文件夹? Check that the paths in the csproj files are correct. 检查csproj文件中的路径是否正确。

If they are different it could be caused by the packages now being restored to a different location. 如果它们不同,则可能是由于软件包现在已还原到其他位置所致。 This could be caused by a NuGet.Config file being checked in specifying a node like this: 这可能是由于在指定这样的节点时检查了NuGet.Config文件引起的:

<add key="repositoryPath" value="..\..\Packages" />

The packages are being restored, by the projects are still looking at the old location. 程序包仍在寻找旧位置,正在恢复软件包。


#3楼

In my case, I had to remove the following from the .csproj file: 就我而言,我必须从.csproj文件中删除以下内容:

<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  <PropertyGroup>
    <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable 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('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>

In fact, in this snippet you can see where the error message is coming from. 实际上,在此代码段中,您可以看到错误消息的来源。

I was converting from MSBuild-Integrated Package Restore to Automatic Package Restore ( http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore ) 我正在从MSBuild集成程序包还原转换为自动程序包还原http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore


#4楼

I had the same issue. 我遇到过同样的问题。 In my case installing the Microsoft.Bcl.Build package fixed the problem. 就我而言,安装Microsoft.Bcl.Build程序包解决了该问题。


#5楼

I had the same issue when i reference the Class library into my MVC web application, 当我将类库引用到我的MVC Web应用程序中时,我遇到了同样的问题,

the issue was the nuget package version number mismatch between two projects. 问题是两个项目之间的nuget软件包版本号不匹配。

ex: my class library had log4net of 1.2.3 but my webapp had 1.2.6 例如:我的课程库的log4net为1.2.3,但我的webapp的为1.2.6

fix: just make sure both the project have the same version number referenced. 修复:只需确保两个项目都引用了相同的版本号。


#6楼

In my case it had to do with the Microsoft.Build.Bcl version. 就我而言,它与Microsoft.Build.Bcl版本有关。 My nuget package version was 1.0.21, but my project files were still pointing to version 1.0.14 我的nuget软件包版本为1.0.21,但我的项目文件仍指向版本1.0.14

So I changed my .csproj files from: 因此,我从以下位置更改了.csproj文件:

  <Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
   <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
    <Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
    <Error Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
  </Target>

to: 至:

 <Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
  <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
    <Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
    <Error Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />

And the build was working again. 并且构建再次正常工作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值