Visual Studio 编译错误 - 计算机中缺少 nuget 包,但 nuget restore 说所有包都已安装?

Posted

技术标签:

【中文标题】Visual Studio 编译错误 - 计算机中缺少 nuget 包,但 nuget restore 说所有包都已安装?【英文标题】:Visual Studio compile error - nuget package missing from computer, but nuget restore says all packages installed? 【发布时间】:2018-08-26 05:04:21 【问题描述】:

这是一个简单的错误,但令人沮丧?我的项目不会重建/编译。错误是:

Severity    Code    Description Project File    Line    Suppression State
Error       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 .\packages\Microsoft.Net.Compilers.1.2.1\build\Microsoft.Net.Compilers.props. Microsoft.Bot.Sample.LuisBot    C:\Users\jmatson\Downloads\retail-info-bot-src\Microsoft.Bot.Sample.LuisBot.csproj  229 

所以我尝试了一个 nuget restore 并得到:

All packages are already installed and there is nothing to restore. Time Elapsed: 00:00:00.0455939
========== Finished ==========

那么谁是对的,谁是错的,这又是如何解决的呢? :/

【问题讨论】:

检查包文件夹,看看错误中提到的那个子文件夹是否存在。如果是这样,请将其删除,然后再次尝试恢复。这发生在我之前,因为文件夹+ nupkg 文件存在(但没有其他内容),所以恢复不起作用。这能解决你的问题吗? 将 Microsoft.Net.Compilers 包更新到最新版本 2.9 并查看是否可行。 如果这一切都不起作用,请检查您的文件夹中是否有 %20(空格)。 Nuget 包不喜欢这样.. 【参考方案1】:

Visual Studio 编译错误 - 计算机上缺少 nuget 包,但 nuget restore 显示所有包都已安装?

首先,确保您没有将\packages 文件夹添加到源代码管理中。如果您添加了它,请将其从源代码管理中删除。

其次,如果您没有使用源代码管理或没有将该文件夹添加到源代码管理中,但仍然存在此问题,则应删除\packages文件夹中的包Microsoft.Net.Compilers.1.2.1,然后在包管理器控制台中使用 NuGet 命令行:

Update-Package -reinstall

强制重新安装包引用到项目中。

文件Microsoft.Net.Compilers.props 位置更改或包文件夹中缺少文件将导致此问题。换句话说,文件Microsoft.Net.Compilers.props 缺少包文件夹但包在那里,你会得到那个错误。

检查similar issue here。

希望这会有所帮助。

【讨论】:

以上是关于Visual Studio 编译错误 - 计算机中缺少 nuget 包,但 nuget restore 说所有包都已安装?的主要内容,如果未能解决你的问题,请参考以下文章

在 Visual Studio 2010 和 Visual Studio 2012 中,带有 col、colgroup、tbody 和 thead 的 HTML 表格标记引发编译错误

由于 lib 错误,Visual Studio 未编译

visual studio编译错误集(转)

visual studio写完程序,编译以后,再改程序,编译器不编译改过后的程序

在 Visual Studio 2008 中将 Fxcop 错误显示为编译错误

如何摆脱 Visual Studio 中的错误?