旧项目无法识别 lambda 表达式 [英] Old project doesn't recognise lambda expression
问题描述
我有一个使用 .net 4.5 的旧项目,我已将其升级到 .net 4.6.2.我使用的是 Visual Studio 2017,所以它应该支持 lambda 表达式,但是当我尝试运行我的项目时,它总是抛出这个错误:
I have an old project that was using .net 4.5 which I have upgraded to .net 4.6.2. I am using visual studio 2017, so it should support lambda expressions, but when I try to run my project it always throws this error:
类、结构或接口成员声明中的无效标记=>"
Invalid token '=>' in class, struct, or interface member declaration
如何使用 c# 6 编译我的项目?我以为只升级目标框架就足够了?
How can I get my project to compile using c# 6? I thought just upgrading the target framework was enough?
推荐答案
尝试使用 Nuget(特定于 2.10 或更高版本)将 Microsoft.Net.Compilers 的引用添加到上述项目,以强制编译器绑定使用 4.6+ 功能.
Try Adding the reference for Microsoft.Net.Compilers to the said project using Nuget (specific for 2.10 or above) to force compiler bindings to use 4.6+ features.
Invalid token class 错误通常是在 Project 中没有正确配置 .Net Compilers 时出现的.
Invalid token class error usually appears when .Net Compilers are not correctly configured in Project.
Install-Package Microsoft.Net.Compilers -Version 2.10.0
注意:如果您使用的是 VS 2017,它应该会自动这样做.
Note: If you're using VS 2017, it should automatically do so.
这篇关于旧项目无法识别 lambda 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!