VS 2017中的元组语法 [英] Tuple syntax in VS 2017
问题描述
在VS2017 RC中,当您尝试使用新的元组语法时,收到以下错误:
In VS2017 RC, when you tried to use new tuple syntax, you received the following error:
CS8179未定义预定义类型'System.ValueTuple`X'或进口
CS8179 Predefined type 'System.ValueTuple`X' is not defined or imported
为了使用元组语法,您必须手动将ValueTuple nuget包导入项目.没什么大不了的,因为它是预发行版本,我认为它将在RTM中进行更改,因此将默认启用.不幸的是,在最终发行版中,情况仍然如此,您必须为每个项目下载nuget包才能使用元组语法.
In order to use tuple syntax, you had to manually import ValueTuple nuget package into the project. Not a big deal, as it was pre-release version and I thought it will be changed in RTM so it will be enabled by default. Unfortunately in the final release version it is still the case and you have to download nuget package for every single project to use tuple syntax.
默认情况下是否有办法为每个项目启用元组语法?
Is there a way to have tuple syntax enabled for every project by default?
推荐答案
根据https://github.com/dotnet/roslyn/issues/13177 ,根据 ITuple
和 ValueTuple
类型将在"".NET Framework 4.7.
According to https://github.com/dotnet/roslyn/issues/13177, the According to the .NET Framework 4.7 release notes, it has been added. Adding it to 4.6.x would break semver. Hence they provided the types as a Nuget package so that projects based on older framework versions can use it.ITuple
and ValueTuple
types will be added to mscorlib in "the first version after" .NET Framework 4.7.
这类似于一个要使用LINQ的.NET 2.0项目,该扩展方法存在于System.Core中,而不是mscorlib.
This is akin to a .NET 2.0 project wanting to use LINQ which the extension methods lived in System.Core, not mscorlib.
您可以做的一个选择是在过渡期间创建引用NuGet程序包的自己的项目模板.
One option you could do is create your own project templates in the interim that reference the NuGet package.
这篇关于VS 2017中的元组语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!