“未定义或导入预定义类型 System.ValueTuple"升级到 .NET 4.7 后

quot;Predefined type System.ValueTuple is not defined or importedquot; after upgrading to .NET 4.7(“未定义或导入预定义类型 System.ValueTuple升级到 .NET 4.7 后)
本文介绍了“未定义或导入预定义类型 System.ValueTuple"升级到 .NET 4.7 后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将现有解决方案从 .NET 4.6.2 升级到 .NET 4.7.此解决方案依赖于几个针对 .NET 4.6.2 的 nuget 包,因此依赖于 nuget 系统.ValueTuple 包.

I'm upgrading an existing solution from .NET 4.6.2 to .NET 4.7. This solution depends on several nuget packages that target .NET 4.6.2 and hence depend on the nuget System.ValueTuple package.

但升级后,我收到一大堆这些构建错误:

But after upgrading, I'm getting a whole bunch of these build errors:

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

按照此处System.ValueTuple 包>,因为其他包都依赖它.(如果我强迫它,它们似乎会爆炸.)

I can't remove the System.ValueTuple package, as suggested in the comments here, because other packages depend on it. (And if I force it, they seem to blow up.)

有什么建议吗?

2017 年 8 月 8 日更新

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

I've figured out that I can remove the System.ValueTuple package, and I can get the solution to compile that way. However, I've got a dozen NuGet packages in the solution which appear to be targeting .NET 4.6.2, and hence require System.ValueTuple as a dependency. I can install those, and then force remove the System.ValueTuple package, but if any of those packages have an update, and I install the update - then the System.ValueTuple package gets installed again, and the system stops building until I remove the package all over again.

换句话说,我可以让它全部工作 - 但它看起来很尴尬和笨拙.肯定有更好的方法来解决这个问题吗?

In other words, I can make it all work - but it seems awkward and kludgy. Surely there's a better way to approach this?

推荐答案

是的,升级到 系统.值元组 4.4.0.

原因如下:

NuGet 包 System.ValueTuple 提供了 C# 元组语法所需的 ValueTuple 类型.在 .NET Framework 4.7 中,我们将类型直接添加到 mscorlib.如果同时使用 NuGet 包和 .NET Framework 4.7,您最终会多次看到相同的类型.这会导致 Stack Overflow 上报告的类似问题.

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.

我们更新了 NuGet 包,以将 .NET Framework 4.7 上的元组类型类型转发到 mscorlib.这统一了类型,因此允许您使用依赖于 System.ValueTuple 的其他库和 NuGet 包,同时仍以 .NET Framework 4.7 为目标.

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.

请参阅发行说明.

这篇关于“未定义或导入预定义类型 System.ValueTuple"升级到 .NET 4.7 后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)