我研究了这个问题,但没有一个解决办法有效。我安装了Visual Studio Professional 2015,我正在使用TFS。我的NuGet版本是3.1.6。这个问题只发生在我的c# Web API/MVC项目中。

我得到以下错误:

这个项目引用了NuGet包(s),这是缺失的 电脑。使用NuGet包还原来下载它们。更多的 信息,见http://go.microsoft.com/fwlink/?LinkID=322105。的 丢失的文件是 . . \ \ Microsoft.Net.Compilers.1.0.0 \制造\ Microsoft.Net.Compilers.props包

I do not have .nuget folder in my solutions. I have a packages folder in the solution and when I delete it, it seems like NuGet does rebuild the dependencies but the project still has the above error. I tried removing the project from TFS and it didn't fix it. Along with the above error, all the references in the project have yellow warning signs and say they are missing. When I checked the NuGet Package Manager for the project, everything that is "missing" has a green tick next to it, including Microsoft.Net.Compilers. I tried adding a new Web API/MVC project and it faced a similar problem where most references such as Owin were "missing" with the yellow warning sign.


当前回答

我通过从.csproj文件中删除这段代码来解决我的问题:

<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>

其他回答

对于在这里遇到我遇到的问题(在构建服务器上恢复了一些包,但不是所有包)的任何人来说,对我来说,难题的最后一块是添加NuGet。config在我的解决方案的根文件中,是. sln文件的兄弟,正如David Ebbo在这里解释的:http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html。

从Ebbo的博客文章来看,文件内容对我来说很简单

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </packageSources>
</configuration>

更新:

v3的NuGet API URL已更改(截至2016年9月)。从https://www.nuget.org/

<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />

这两个答案的组合对我来说是有效的。首先,我修改了.csproj文件以删除对1.0.0版本的引用

< Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild" >

  ----Error---

< /Target>

然后真的

Update-Package -Reinstall

它成功了。

我通过从.csproj文件中删除这段代码来解决我的问题:

<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>

我的问题是NuGet不能自动获取/更新包,因为完整的文件路径太大了。通过将我的解决方案移动到我的文档中的一个文件夹而不是一个深度嵌套的文件夹来修复。

然后可以右键单击解决方案并选择“恢复NuGet包”(如果您只是构建它并让它为您完成它,这可能是不必要的),然后选择“管理解决方案的NuGet包”以将所有包更新到最新版本。

这是从微软网站上下载的一个ASP MVC应用程序示例的解决方案。

我正在使用VS2012,遇到同样的错误。我从.csproj文件中删除了下面的Target标记,它开始编译,没有出现任何错误。

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  -- Error messages within Target Tag
</Target>