我已经安装了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´未定义或导入
根据这篇博文,这个功能在默认情况下应该是“开启”的。
我做错了什么?
我必须检查System.ValueTuple.dll文件是否在源代码控制下,并纠正其在.cssproj文件中的引用:
右键单击解决方案中的每个项目
卸载项目
编辑.cssproj文件:change
< Reference Include="System. "ValueTuple”>
< 提示路径>
.... ProjectName \ ProjectName obj \发行包PackageTmp \ bin \ ValueTuple。等系统。
</HintPath >
< /引用>
成
< Reference Include="System. "ValueTuple”>
< 提示路径>
ValueTuple \ packages系统。4 . 4。0李勃\ netstandard1 ValueTuple 0 \系统。等等
</HintPath >
< /引用>
保存更改并重新加载项目
找到System.ValueTuple.dll并保存到这个文件夹中
将此文件的引用添加到源代码控制中
(可选):7。用这种方法解决另一个.dll文件的相同问题
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.
我不得不重构以使用结构体代替。我希望其他人将来不要继续遇到这个问题,但如果你最终像我们一样被难住了,这可能会有帮助。