58

After Visual Studio 2017 was released I wanted to try to create simple console project with new C# 7 features. I expected that I simply download new Visual Studio 2017, then create new console project and can use new C# 7 features. But I can't.

I can use some features, like Tuples if I install NuGet package System.ValueTuple.

But for other features, I don't know what I need to do. For example this NuGet issue.

Do I need to do all this dirty install now? Or I can enable c# 7 features in a more simple way?

chromigo
  • 1,134
  • 1
  • 15
  • 25
  • Possible duplicate of [Enabling c# 7 in a asp.net application](https://stackoverflow.com/questions/42744689/enabling-c-sharp-7-in-a-asp-net-application) – Hassan Abdullah Jun 29 '17 at 12:29

3 Answers3

35

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.

Community
  • 1
  • 1
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
  • 3
    See these [comments](https://stackoverflow.com/questions/42657839/tuple-syntax-in-vs-2017) for a rather animated discussion of the same thing. – Bradley Uffner Mar 08 '17 at 15:47
  • @BradleyUffner yea, that discussion is where I learned about the "built in to the next version" part. – Scott Chamberlain Mar 08 '17 at 15:48
  • 2
    Hi, @ScottChamberlain. So, for each feature, I need to install specific NuGet package? Is there anywhere list of these packages for all new features of C # 7? Or I need to manually check each feature and find this package ... or wait .net 4.6.3+ – chromigo Mar 08 '17 at 15:51
  • 2
    Also the VS 2017 release notes link to the Github issues, but the documentation in those issues makes references to features that are not implemented yet such as record types in the case of the pattern matching issue. If there were MSDN documentation pages with proper examples this wouldn't be an issue. – Dustin Kingen Mar 08 '17 at 15:55
  • 5
    Only Tuples and not task returns require the special types. [If you see the documentation for C# 7](https://learn.microsoft.com/en-us/dotnet/articles/csharp/csharp-7) you can see only those two features say they rely on NuGet packages. – Scott Chamberlain Mar 08 '17 at 15:59
  • 2
    @ScottChamberlain Hmm, even that documentation is out of date. For tuples and tasks it says the NuGet package is only required for "Visual Studio 15 Preview 5 and earlier". That implies that it isn't required for the production release. That really needs to get updated. – Bradley Uffner Mar 08 '17 at 16:12
  • Check this link https://stackoverflow.com/questions/42744689/enabling-c-sharp-7-in-a-asp-net-application – Hassan Abdullah Jun 29 '17 at 12:16
21

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:

Tao Yue
  • 696
  • 5
  • 9
2

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

M.Hassan
  • 10,282
  • 5
  • 65
  • 84