我已经安装了Visual Studio 15 Preview 3,并尝试使用新的元组功能
static void Main(string[] args)
{
var x = DoSomething();
Console.WriteLine(x.x);
}
static (int x, int y) DoSomething()
{
return (1, 2);
}
当我编译时,我得到错误:
预定义类型“系统”。ValueTuple´2´未定义或导入
根据这篇博文,这个功能在默认情况下应该是“开启”的。
我做错了什么?
We were seeing this same issue in one of our old projects that was targeting Framework 4.5.2. I tried several scenarios including all of the ones listed above: target 4.6.1, add System.ValueTuple package, delete bin, obj, and .vs folders. No dice. Repeat the same process for 4.7.2. Then tried removing the System.ValueTuple package since I was targeting 4.7.2 as one commenter suggested. Still nothing. Checked csproj file reference path. Looks right. Even dropped back down to 4.5.2 and installing the package again. All this with several VS restarts and deleting the same folders several times. Literally nothing worked.
我不得不重构以使用结构体代替。我希望其他人将来不要继续遇到这个问题,但如果你最终像我们一样被难住了,这可能会有帮助。