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


当前回答

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.

其他回答

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

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

我收到了这个令人沮丧的消息。最后对我有用的是删除/包内的所有文件和文件夹,让VS在下次构建时重新获取所有内容。

遇到这个问题

按以下步骤求解

清除packages文件夹中的内容(先备份) 使用“更新-包-重新安装”从包管理控制台的NuGet中重新获取和重新安装包(Tools -> NuGet包管理器->包管理控制台) 从.csproj文件中删除冗余路径。注意:NuGet会添加新的路径到csproj文件,但它不会删除旧的路径… (有一些机会csproj文件有多个路径为同一文件)

为什么我们需要“Microsoft.Net.Compilers.props”? 它将提供“\roslyn”文件夹。如果没有它,你可能仍然可以编译程序,但不能使用@{html.RenderPartial…}

在我的案例中工作的解决方案- Visual Studio 2015 enterprise,项目.NET 4.6.1

升级至Update 3 安装Web开发工具

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