How can I enable all features of C# 7 in Visual Studio 2017 project?

家住魔仙堡 提交于 2019-11-30 05:34:09
Scott Chamberlain

For arbitrary task-like types you linked to in the 2nd part of your question you need to include the System.Threading.Tasks.Extensions package.

The reason you need these NuGet packages is because the new language features rely on new types added to the .NET framework. The new types that the C# language features depend on will not be "built in to the framework" until the next minor version released after 4.6.2 to not break SemVer1. So unless you are building a project using that next version of the framework you will need to use the NuGet packages to get the features to work.

This is no different than getting extension methods to work in a .NET 2.0 project. You can use extension methods but you need to use a NuGet package (or add the code yourself) to get the types it relies on to be added to your project.


1: So 4.7 or 5.0, whatever they decide to call it, if there is a 4.6.3 it will not be in that version because that is not a minor release version bump, that is a patch version bump and you can't make API changes in a patch version bump without violating Semantic Versioning.

Any project that targets .NET 4.7 can use C# 7 tuples without adding a Nuget package. You'll have to install it manually:

  1. Upgrade to Windows 10 Creator's Update (10.0.15063), or install .NET Framework 4.7 on other versions of Windows: https://www.microsoft.com/en-us/download/details.aspx?id=55170
  2. From the Start menu, run Visual Studio Installer and click Modify. Go to "Individual components" and check the following two components:
    • .NET Framework 4.7 SDK
    • .NET Framework 4.7 targeting pack

It doesn't work out-of-the-box on Windows 10 Creator's Update because Microsoft omitted the .NET 4.7 components from the ".NET desktop environment" workload. I filed a bug, but they closed it as Not a Bug:

Vs2017 update 3 can support c#7.1 but it's configured by default to support c#7.0.

You can modify the setting of your project and select c# 7.1

for more details how to configure vs2017.3 to support last version of c#7.1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!