【问题标题】:Error using nuget in VS2012 "missing packages"在 VS2012“缺少包”中使用 nuget 时出错
【发布时间】:2013-09-20 22:26:58
【问题描述】:

当我在 VS2012 中构建项目时,我收到以下错误消息

This project references NuGet package(s) that are missing on this computer. 
Enable NuGet Package Restore to download them. 

我为 NuGet 设置了 nuget 选项以下载丢失的包。

但我仍然得到错误。 我已经安装了 nugget 2.7。随着VS2012更新3

【问题讨论】:

  • 您在 Visual Studio 中有什么类型的项目?项目中是否有 .nuget 文件夹?

标签: visual-studio nuget nuget-package-restore


【解决方案1】:

请按照以下步骤操作:

第 1 步: 请通过右键单击解决方案启用 Nuget 包还原 [如下截图所述]

第 2 步:[如果按照第 1 步解决问题/错误,请按此操作] 如果您遇到问题,请在记事本中打开 .csproj 文件并检查可能看起来像这样的包路径

所以你的解决方案目录结构会是这样的:

\SolutionDirectory\

包目录:

\SolutionDirectory\packages

项目目录:

\SolutionDirectory\ProjectName\ProjectName.csproj

请在记事本中打开此 .csproj [出现错误] 并搜索软件包路径并将其更新到其相关路径。

例如我的 .csproj 包含,如果 .csproj 文件包含 ..\..\packages 则使用 ..\packages 更新该路径

【讨论】:

  • 否决,因为这是不再推荐的旧包还原方法。 blog.davidebbo.com/2014/01/… 和 docs.nuget.org/docs/reference/package-restore 和
  • 同意 - 遵循这条路径,您可以告别通过 Visual Studio Online TFS、Web 发布或其他较新的 Microsoft 部署模型部署的任何内容
  • 仍然为我工作。我必须将包路径从 \packages\ 更改为 ..\packages\.
【解决方案2】:

正如 Dan 所暗示的,如果您的解决方案有一个 .nuget 文件夹(来自启用包还原),那么根据 http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore,nuget 2.7 的自动包还原功能将被禁用。

如果禁用了自动包恢复,那么任何安装项目目标文件的包都会导致构建失败,直到您在解决方案中手动恢复该包,如 http://blogs.msdn.com/b/dotnet/archive/2013/06/12/nuget-package-restore-issues.aspx 所述。 (请注意,由于 nuget 2.7 自动包恢复可用,链接中描述的解决方法已经过时。)

因此,如果这两件事都成立,则删除 .nuget 文件夹中的 NuGet.targets 文件,然后 Nuget 将在调用 MSBuild 之前恢复丢失的包。您也可以删除 .nuget 文件夹中的 nuget.exe,因为它将不再使用。

【讨论】:

  • 不,不是文件夹的存在而是 nuget.targets ;) "由于 NuGet.targets 文件的存在决定了 NuGet 是否会继续使用 MSBuild-Integrated 方法"
  • 我也没有 .nuget 文件夹,但使用此答案中的第一个链接解决了我的构建问题。必须删除我的 .csproj 文件中的一些“EnsureXXXXXXPackageBuildImports”代码,这些代码由于缺少 NuGet DLL 而阻止构建。
【解决方案3】:

这些答案对我找到解决方案非常有帮助。由于解决我的具体问题需要多一步,我在这里报告它以防对其他人有帮助。 我得到的错误:

Error   117 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 ..\..\Windows Phone 8\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets.

我按照答案删除了所有建议的内容,但错误仍然不断出现。我终于通过删除 .csproj 中的以下行来摆脱它:

<Error Condition="!Exists(...

【讨论】:

  • 这为我节省了很多痛苦。谢谢!
  • 谢谢。评论如下:
【解决方案4】:
  1. 删除 NuGet
  2. 使用记事本从项目文件中删除依赖 NuGet 的目标
  3. 安装最新版本的 NuGet
  4. 重新启动 Visual Studio 并重新打开项目/解决方案。
  5. 如果您愿意,可以使用最新版本的 NuGet 添加新的 .nuget 文件

【讨论】:

  • 我一直在网上寻找解决此问题的方法。这是唯一有效的。 nuget恢复?呸!感谢这个解决方案。应标记为已接受。
  • 它完全解决了我的问题,按照你的步骤,我可以从nuget包管理器下载其他依赖项,谢谢
  • 如何从项目文件中删除 NuGet 数据:docs.nuget.org/consume/package-restore/…
【解决方案5】:

在记事本中打开csproj 文件并从此处删除Error Condition 元素(或使这些条件有效):

<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'))" />
    <Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.101.0\build\net45\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.101.0\build\net45\System.Data.SQLite.Core.targets'))" />
  </Target>

【讨论】:

    【解决方案6】:

    从解决方案中删除 .nuget 目录(如果存在)。编辑项目文件并删除包含对 .nuget 文件夹的引用的 Import 和 Target 元素,保存并重新加载项目。

    【讨论】:

      【解决方案7】:

      试试这个,

      1. 列表项
      2. 右键单击解决方案
      3. 点击管理 NuGet
      4. 点击左下角设置
      5. 选中允许 NuGet 下载丢失的包。

      【讨论】:

        【解决方案8】:

        只需右键单击解决方案并“启用 NuGet 包还原”即可解决我的问题。

        【讨论】:

          猜你喜欢
          • 2015-11-22
          • 1970-01-01
          • 2021-11-01
          • 2016-06-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-02-21
          相关资源
          最近更新 更多