此项目引用此计算机上缺少的NuGet包

Aus*_*ris 284 msbuild visual-studio-2010 visual-studio nuget

我有一个ASP.NET MVC5应用程序,昨天工作,现在我在尝试构建时收到此错误:

此项目引用此计算机上缺少的NuGet包.

我检查了两个选项,允许nuget自动下载并安装检查/打开的缺失包.我还尝试删除packages文件夹中的所有文件,然后让nuget重新下载它们.此外,当我打开nuget并寻找更新时,它说没有必要安装.我无法想象还有什么可以超越这个令人惊讶的恼人问题.

Lor*_*sen 430

在我的情况下,我不得不从.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>
Run Code Online (Sandbox Code Playgroud)

实际上,在此代码段中,您可以看到错误消息的来源.

我正在从MSBuild集成包恢复转换为自动包恢复(http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore)

  • 这对我有用,但我只需要删除<Target> </ Target>元素.如果我删除<Import>元素,VS [2013]似乎还原它. (9认同)
  • 这严重令人难以置信。为什么微软让一切变得如此困难? (9认同)
  • 如果可以删除,为什么它在第一个位置? (7认同)
  • 我喜欢只涉及删除内容的解决方案。 (5认同)
  • OK9999,在某一时刻,您必须从早期版本的 Visual Studio 启用它,方法是右键单击解决方案并选择“启用 NuGet 包还原”,这是旧的方式。我们不再需要那个了 (3认同)
  • 当您更改项目目录名称或路径时,通常会发生此错误。编辑 .proj 文件并替换新的目录名称以恢复包的路径。 (2认同)

Iva*_*ago 75

一种解决方案是从.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>
Run Code Online (Sandbox Code Playgroud)

怎么样?

  1. 右键单击项目.卸载项目.
  2. 右键单击项目.编辑csproj.
  3. 从文件中删除该部分.保存.
  4. 右键单击项目.重新加载项目.

  • @IvanSantiago 您可以:将其添加为评论,或者,使用 How To 编辑原始答案。 (5认同)
  • @IvanSantiago**上面已经回答了同样的解决方案!****投票!... (3认同)
  • 当您将项目从一个地方移动到另一个地方时,这非常有效。 (2认同)
  • @ClintEastwood 我的回答解释了**如何**去做。这就是区别。如果用户正在寻找 **HOW TO** 我的答案,与上面的答案相反。 (2认同)

Nik*_* G. 46

在我的情况下,它发生在我将我的解决方案文件夹从一个位置移动到另一个位置后,重新组织了一点,并在此过程中其相对文件夹结构发生了变化.

所以我必须在我的.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')" />
Run Code Online (Sandbox Code Playgroud)

  <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')" />
Run Code Online (Sandbox Code Playgroud)

(注意从改变..\packages\packages\.在你的情况下它可能是一个不同的相对结构,但你明白了.)

  • 类似的问题....我已将.csproj文件移动到目录结构中的一个级别,并且必须从"..\..\packages\..."更改为"..\packages\...". (3认同)
  • 我有一个类似的问题,但真的很奇怪.我在子解决方案模块中使用它,所以在该解决方案中它很好,但是当我从另一个解决方案引用该解决方案时,包在不同的位置.我在整个.csproj中将..\packages更改为$(SolutionDir)包并修复了它. (2认同)
  • 如果您不想手动使用.csproj文件,我发现记下您为项目安装的所有nuget软件包,删除它们并重新安装它们为我解决了这个问题.当我遇到这个问题时,我试图从一个解决方案中删除一个项目,放入它自己的git存储库. (2认同)

M.A*_*M.A 21

通过右键单击我的解决方案,然后单击" 启用NuGet包还原"选项,我可以轻松解决此问题

(PS:确保您具有Nuget安装工具 - >扩展和更新 - > Nuget包管理器for Visual Studio 2013.如果没有先安装此扩展)

希望能帮助到你.

  • 这是恢复nuget包的旧方法,应该避免. (6认同)
  • @TheMuffinMan:你能澄清一下新方法是什么以及为什么要避免这种方式(考虑到VS 2013错误输出告诉你这样做)? (2认同)
  • @CantrianBear导航到这个页面https://docs.nuget.org/consume/package-restore并找到名为"MSBuild-Integrated Package Restore"的部分.这是旧的方式,它列出了为什么要使用新方法的一些原因. (2认同)

小智 17

在我的情况下,它与Microsoft.Build.Bcl版本有关.我的nuget包版本是1.0.21,但我的项目文件仍然指向版本1.0.14

所以我改变了我的.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>
Run Code Online (Sandbox Code Playgroud)

至:

 <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" />
Run Code Online (Sandbox Code Playgroud)

构建再次运行.


Wil*_* Jr 12

我有同样的问题。我在复制现有项目并将其传输到我的解决方案目录的文件夹中并将其作为现有项目添加到我的空解决方案时遇到了它。所以我必须编辑我的 csproj 文件并查找这行特定的代码,大多数情况下,这可以在最后几行找到:

  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Run Code Online (Sandbox Code Playgroud)

在该行之后,我必须将这些注释掉:

  <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. 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\EntityFramework.6.4.0\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\..\packages\EntityFramework.6.4.0\build\EntityFramework.props'))" />
    <Error Condition="!Exists('..\..\..\..\..\packages\EntityFramework.6.4.0\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\..\packages\EntityFramework.6.4.0\build\EntityFramework.targets'))" />
  </Target>
  <Import Project="..\..\..\..\..\packages\EntityFramework.6.4.0\build\EntityFramework.targets" Condition="Exists('..\..\..\..\..\packages\EntityFramework.6.4.0\build\EntityFramework.targets')" />
Run Code Online (Sandbox Code Playgroud)

您的解决方案将提示您的项目发生了更改,只需选择重新加载全部:

在此处输入图片说明 然后在重建我的解决方案后一切正常。


RAM*_*RAM 11

如果您正在使用TFS

从解决方案的文件夹中删除NuGet.exeNuGet.targets文件.nuget.确保文件本身也从解决方案工作区中删除.保留NuGet.Config文件以继续绕过将包添加到源代码管理.

编辑解决方案中的每个项目文件(例如.csproj,.vbproj)并删除对该NuGet.targets文件的任何引用.在您选择的编辑器中打开项目文件,然后删除以下设置:

<RestorePackages>true</RestorePackages>  
...
<Import Project="$(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>
Run Code Online (Sandbox Code Playgroud)

如果您不使用TFS

.nuget从解决方案中删除该文件夹.确保文件夹本身也从解决方案工作区中删除.

编辑解决方案中的每个项目文件(例如.csproj,.vbproj)并删除对该NuGet.targets文件的任何引用.在您选择的编辑器中打开项目文件,然后删除以下设置:

<RestorePackages>true</RestorePackages>  
...
<Import Project="$(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>
Run Code Online (Sandbox Code Playgroud)

参考:迁移MSBuild集成解决方案以使用自动包还原


Ami*_*oon 10

删除了 .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>
Run Code Online (Sandbox Code Playgroud)


psy*_*ych 8

包裹是否可能已恢复到错误的文件夹?检查csproj文件中的路径是否正确.

如果它们不同,则可能是由于现在正在将包恢复到其他位置而导致的.这可能是由于在检查NuGet.Config文件时指定了这样的节点:

<add key="repositoryPath" value="..\..\Packages" />
Run Code Online (Sandbox Code Playgroud)

这些包正在恢复,项目仍在查看旧位置.


mhe*_*man 6

我遇到过同样的问题.在我的情况下,安装Microsoft.Bcl.Build包修复了问题.


小智 5

一种解决方案是从 .csproj 文件中删除以下内容:

<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
Run Code Online (Sandbox Code Playgroud)

此项目引用此计算机上缺少的 NuGet 包。启用 NuGet 包还原以下载它们。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105。丢失的文件是 {0}。


小智 5

首先要尝试的是右键单击解决方案并选择“还原 Nuget 包”。

在我的情况下,这不起作用,所以我遵循了一些关于删除项目文件中的“导入”和“目标”的建议,这适用于我的 3 个项目中的 2 个,但在最后一个中出现了不同的错误。

有效的是打开包管理器控制台并运行:

Update-Package -reinstall -ProjectName MyProjectName
Run Code Online (Sandbox Code Playgroud)

这需要一些时间,但由于它重新安装了所有包,您的项目将毫无问题地编译