Value Tuples in C# 7: Please Tell Me I'm Doing This Wrong

Datetime:2017-04-20 05:21:59         Topic: Visual Studio  C#          Share        Original >>
Here to See The Original Article!!!

I really need someone to tell me that I'm doing this wrong. Because what I found is that I need to install a NuGet package in order to use a C# language feature .

The Discovery

I was doing some experimentation last night, and I decided that I would try to use value tuples, a new feature in C# 7. (Long story short, I was trying to implement a Fibonacci sequence in C# using a more declarative approach (similar to what I did in F# last year ).)

So I fired up Visual Studio 2017, got a working implementation going with TDD (I'll write about that in a future article), then I went to refactor it to use a value tuple.

As a first step, I created a local variable:

That's when I ran into a problem. Red squigglies? I double checked the docs online to make sure I was using the right syntax. Yep.

Here's the build error:

Great. Now what? "System.ValueTuple" doesn't show up in my available assembly references (and yet, somehow the compiler knows about it).

Looking at the Microsoft docs ( https://docs.microsoft.com/en-us/dotnet/articles/csharp/whats-new/csharp-7#tuples ), I came across this note:

But I'm not using a Preview. I have the release version of Visual Studio 2017 (Version 15.1 (26403.7) Release). Surely I don't need a NuGet package.

But the only way I could get this to work was to install the NuGet package:

After installing this, my tuple started working fine:

The Environment

  • Visual Studio 2017 Enterprise (Version 15.1 Release)
  • .NET Version 4.6.2
  • Windows 10 (who knows what actual version, not the Creator's Update)

Please, Please, Please

I really need someone to tell me that I'm doing this wrong. Do I really need to install a NuGet package to use a language feature?

If I need to install a package, is it really a language feature? Or is it just another library.

[Update: The package is not needed with .NET 4.7. But as of today, .NET 4.7 (and the ability to target it in Visual Studio) is *only* available for Windows 10 Creator's Update.]

I am not connected to the internet 24 hours a day. And when I am, I don't always have a high speed connection. I already find myself going back to Visual Studio 2015 periodically just because I have local help installed there.

Visual Studio has been a really awesome development environment. But I find it harder and harder to develop with Visual Studio 2017.

So, please tell me that I'm doing something wrong. I want my peace of mind back.








New