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


当前回答

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

其他回答

只要启用NuGet包恢复。 右键单击您的解决方案>选择“启用NuGet包恢复”。

这将创建带有NuGet的. NuGet文件夹。配置文件,并解决了我的问题。

注意——这将更新整个解决方案的包,而不仅仅是项目。

如果你还有一个丢失的nuget包,在构建解决方案时给出错误,请使用以下命令,从工具> nuget包管理器>包管理器控制台使用nuget命令控制台。它将重新安装您的所有当前包。

Update-Package –reinstall

更新:

您可以将特定的项目名称作为参数传递。

Update-Package –reinstall -ProjectName SampleApp

正如许多人建议的那样,删除<Target>标记可以使其可编译。然而,当您为测试项目这样做时,要注意它有一个副作用。

我得到了与MSTest相关的错误。TestAdapter nuget包在编译时。通过移除<Target>标签解决了这个问题。尽管它使构建成功,但测试方法变得不可发现。测试资源管理器不会列出该项目中的测试方法,运行测试或调试测试也不能很好地工作。

我在使用Visual Studio 2017和.Net框架4.7时遇到了这种情况,在其他版本中也很可能发生这种情况

我用以下步骤解决了同样的问题

Removed package <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net46" /> from package.config file. Edit the .csproj project file and removed the below settings. <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\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />   </Target> Go to package manager console and run the command Update-Package –reinstall

第2点和第3点是其他用户提出的,我很感谢这些用户。第一点,从包中删除Microsoft.CodeDom.Providers.DotNetCompilerPlatform。配置文件更重要。此外,在运行第3点中提到的命令之后,问题就解决了。删除所有不需要的包并更新所需的包引用。

希望这能帮助到一些人。

不同的用户名是常见的原因,Nuget下载一切到:“C:\Users\USER_NAME\source\repos”,如果你之前在不同的用户名上设置了项目。csproj文件可能仍然包含旧的用户名,只需打开它,并做一个搜索替换“C:\Users\ old_user_name \source\repos”到“C:\Users\NEW_USER_NAME\source\repos”。