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


当前回答

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

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

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

其他回答

我也遇到了同样的问题,原来我引用的一个项目在解决方案目录之外(因此没有共享相同的“/packages”文件夹)。对我来说有效的解决方案是打开参考项目的解决方案并在那里构建它。一旦项目建成,错误就消失了。

在我的例子中,*中缺少<RestorePackages>true</RestorePackages>。csproj文件。没有必要删除我在前面的回答中看到的代码片段。

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

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

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

Not sure if this will help anyone, but I had this issue come up when I deleted the source code from my local machine without having ever saved the solution file to TFS. (During initial development, I was right-clicking and checking in the project in Solution Explorer, but forgot to ever check in the solution itself.) When I needed to work on this again, all I had in TFS was the .csproj file, no .sln file. So in VS I did a File --> Source Control --> Advanced -- Open from Server and opened the .csproj file. From there I did a Save All and it asked me where I wanted to save the .sln file. I was saving this .sln file to the project directory with the other folders (App_Data, App_Start, etc.), not the top level directory. I finally figured out that I need to save the .sln file up a directory from the project folder so it's on the same level as the project folder. All my paths resolved and I was able to build it again.