我研究了这个问题,但没有一个解决办法有效。我安装了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.


当前回答

我找不到任何解决方案,所以我添加了一个nuget.exe副本和一个powershell脚本到解决方案的根目录,称为prebuild。Ps1的以下内容。

$nugetexe = 'nuget.exe'
$args = 'restore SOLUTION_NAME_HERE.sln'
Start-Process $nugetexe -ArgumentList $args

在我的构建中,我在预构建脚本路径中调用这个powershell脚本

其他回答

注释掉.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\Costura.Fody.2.0.1\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.2.0.1\build\Costura.Fody.targets'))" />
<Error Condition="!Exists('..\packages\Fody.3.1.3\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.3.1.3\build\Fody.targets'))" />

对我来说,包在正确的路径下,但是包文件夹中的构建文件夹不是。我只是删除了它所说的所有丢失的包并重新构建解决方案,它成功地创建了构建文件夹和.props文件。所以错误消息是正确的,它告诉我有什么东西漏了。

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

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

我得到了这个错误的修复,实际上我有一个不同版本的MSTest.TestAdapter(1.3.2)在我的包文件夹和在.csproj文件引用指向MSTest.TestAdapter(1.1.0)。我已经将所有MSTest.TestAdapter(1.1.0)替换为MSTest.TestAdapter(1.3.2),这解决了我的问题。

解决方案中的文件夹名为”。网络项目”。通过将其重命名为“NET Project”,一切都很正常。所以一开始的点是个坏主意。