Invalid option 'latest' for /langversion; must be ISO-1, ISO-2, Default or an integer in range 1 to

57 篇文章 1 订阅

You may be thinking that C# 7 features are already supported with Visual Studio 2017 and you do not need to make any changes for that. Yes, you are almost right but this is not 100% true.

Wait for a while and let me explain. If you open Visual Studio 2017 and start compiling the code which was introduced with C# 7 then most of the features will be compiled successfully and you do not need to make any changes for the language version. 

But if you will check the currently selected C# language version then you will find that it is “default” not “C#7.0”. Let’s check it.

  1. Open Solution Explorer inside Visual Studio 2017
  2. Select the project and right click on it to open the context menu and select “Properties”.

    C#
  1. Inside the Project property window click on “Build Tab” and the click on “Advanced…” button.

    C#

    It will open the “Advanced Build Settings” window.
  1. Inside the “Advanced Build Settings” window you can see that the selected language version is “default”.

    C#

    The great thing is that by selecting the “default” option we can compile most of the language features of C# 7.
  1. Now select the language version as C#7.0 and compile the code.

    C#

When you will compile the C# 7 code with this option then then you may get compilation error like:

Error CS1617 Invalid option '7' for /langversion; must be ISO-1, ISO-2, Default or an integer in range 1 to 6.

But this error is not with all type of application. When I am compiling a console application with language version C# 7 then it is being compiled successfully whereas the web app is giving compile time error.

C#

So far you have seen the problem. Now you may be thinking, what is the solution? So the solution is very simple. You will need to install the latest version of Microsoft.Net.Compilers (version 2.0 or any upper version).

C#

After installing Microsoft.Net.Compilers your web app will compile successfully with language version C#7.0.

But still you may need some more Nuget packages depending on language features you are using e.g. you need to install “System.ValueTuple” for tuples.

For complete list of C# 7 features you can visit following article,

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值