c# - 升级到 .NET 4.7 后为 "Predefined type System.ValueTuple is not defined or imported"

标签 c# .net nuget

我正在将现有解决方案从 .NET 4.6.2 升级到 .NET 4.7。此解决方案依赖于几个以 .NET 4.6.2 为目标的 nuget 包,因此依赖于 nuget System.ValueTuple。包。

但是在升级之后,我遇到了一大堆这些构建错误:

错误 CS8179 未定义或导入预定义类型“System.ValueTuple`2”

我无法删除 System.ValueTuple 包,如评论中所建议的那样 here ,因为其他包依赖于它。 (如果我强制它,它们似乎会爆炸。)

有什么建议吗?

2017 年 8 月 8 日更新

我发现我可以删除 System.ValueTuple 包,并且我可以获得以这种方式编译的解决方案。但是,我在解决方案中有十几个 NuGet 包,它们似乎以 .NET 4.6.2 为目标,因此需要 System.ValueTuple 作为依赖项。我可以安装它们,然后强制删除 System.ValueTuple 包,但如果这些包中的任何一个有更新,我就安装更新 - 然后是 System.ValueTuple软件包再次安装,系统停止构建,直到我再次删除该软件包。

换句话说,我可以让一切正常运行——但它看起来很笨拙。当然有更好的方法来解决这个问题?

最佳答案

是的,升级到System.ValueTuple 4.4.0 .

原因如下:

The NuGet package System.ValueTuple provides the ValueTuple types which are required for the C# tuple syntax. In .NET Framework 4.7 we've added the types directly to mscorlib. If you use both, the NuGet package, as well as .NET Framework 4.7 you'll end up seeing the same types multiple times. This results in issues like this one reported on Stack Overflow.

We've updated the NuGet package to type forward the tuple types on .NET Framework 4.7 to mscorlib. This unifies the types and thus allows you to consume other libraries and NuGet packages that depend on System.ValueTuple while still targeting .NET Framework 4.7.

参见 release notes .

关于c# - 升级到 .NET 4.7 后为 "Predefined type System.ValueTuple is not defined or imported",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45339914/

相关文章:

.net - 使用 NuGet 恢复预发行包

c# - Entity Framework 4.2 : Getting proper database errors

c# - 使用自定义 JsonConverter 反序列化接口(interface)列表?

c# - 从 Serilog 滚动文件在 macOS 中不起作用

c# - 在 WinForm 中验证数据

.net - 哪些 .NET 兼容的图形数据库解决方案具有良好的业绩记录?

c# - 如何选择按月分组的行

.net - NuGet Enterprise - 不同成熟度级别包的最佳实践

c# - 如何在 C# 中的 GUI 线程上启动一系列定时事件?

c# - 无法加载System.Threading.Tasks.Extensions