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

时间:2022-12-17 16:05:12

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.

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

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

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

Error CS8179 Predefined type 'System.ValueTuple`2' is not defined or imported

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

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.)

我无法删除System.ValueTuple包,如此处的注释所示,因为其他包依赖于它。 (如果我强迫它,它们似乎会爆炸。)

Any suggestions?

有什么建议么?

Update 8/8/17

更新8/8/17

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.

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

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

换句话说,我可以使一切工作 - 但它似乎很尴尬和kludgy。当然有更好的方法来解决这个问题吗?

2 个解决方案

#1


23  

Yes, upgrade to System.ValueTuple 4.4.0.

是的,升级到System.ValueTuple 4.4.0。

Here is why:

原因如下:

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包System.ValueTuple提供了C#元组语法所需的ValueTuple类型。在.NET Framework 4.7中,我们已将类型直接添加到mscorlib。如果你同时使用NuGet包,以及.NET Framework 4.7,你最终会多次看到相同的类型。这会导致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.

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

See release notes.

请参阅发行说明。

#2


3  

In Visual Studion ,NuGet package System.ValueTuple provides the ValueTuple types. So Update System.ValueTuple to latest version v4.4.0. Means Upgrade the System.ValueTuple to higher version then the current or previous one.

在Visual Studion中,NuGet包System.ValueTuple提供了ValueTuple类型。所以将System.ValueTuple更新到最新版本v4.4.0。意味着将System.ValueTuple升级到更高版本,然后升级到当前版本或上一版本。

#1


23  

Yes, upgrade to System.ValueTuple 4.4.0.

是的,升级到System.ValueTuple 4.4.0。

Here is why:

原因如下:

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包System.ValueTuple提供了C#元组语法所需的ValueTuple类型。在.NET Framework 4.7中,我们已将类型直接添加到mscorlib。如果你同时使用NuGet包,以及.NET Framework 4.7,你最终会多次看到相同的类型。这会导致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.

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

See release notes.

请参阅发行说明。

#2


3  

In Visual Studion ,NuGet package System.ValueTuple provides the ValueTuple types. So Update System.ValueTuple to latest version v4.4.0. Means Upgrade the System.ValueTuple to higher version then the current or previous one.

在Visual Studion中,NuGet包System.ValueTuple提供了ValueTuple类型。所以将System.ValueTuple更新到最新版本v4.4.0。意味着将System.ValueTuple升级到更高版本,然后升级到当前版本或上一版本。