Tuple syntax in VS 2017
Asked Answered
L

1

25

In VS2017 RC, when you tried to use new tuple syntax, you received the following error:

CS8179 Predefined type 'System.ValueTuple`X' is not defined or imported

In order to use tuple syntax, you had to manually import ValueTuple nuget package into the project. Not a big deal, as it was pre-release version and I thought it will be changed in RTM so it will be enabled by default. Unfortunately in the final release version it is still the case and you have to download nuget package for every single project to use tuple syntax.

Is there a way to have tuple syntax enabled for every project by default?

Lardy answered 7/3, 2017 at 20:36 Comment(29)
What makes you think it would have changed? Did you see release notes documenting such a change?Apulia
what version of the framework/.net are you targetting?Paripinnate
@DavidL It would be reasonable, as tuple syntax is now an integral part of the language and should be always available. It's weird and uncomfortable to download nuget packages just to use a plain language feature.Lardy
@Daniel A. White it happens on all target frameworks, including 4.6.2.Lardy
why would you expect visual studio to add something you didn't ask for?Paripinnate
@Lardy considering the entire point of the new direction of .NET is "pay to play" and considering that it was present in RC and considering you did not in fact see anything to the contrary in release notes, I'm not certain why you are surprised.Apulia
@Daniel A. White For the same reason you have variables and loops enabled in every project and you don't have to install anything more. Tuple syntax is now part of the language, just like loops or classes.Lardy
@Lardy but the compiler is generating code that needs a new type... the compiler can't just provide that for you...Paripinnate
.Net wouldn't be where it is now if you had to have a nuget package to use for loops, and another one to use multiplication. If the new Tuple syntax is actually part of the language, then it should be a first class citizen of the language, and not require external packages.Poker
Daniel A. White The complier can provide me int and string types, as well as regular System.Tuple and thousands of other classes that are available in every project. I don't see why c# 7.0 tuples are any different.Lardy
@Lardy the compiler doesn't provide those things - those things live in mscorlib which is the default. ValueTuple is brand new and can't just be added to existing librariesParipinnate
@DanielA.White Why not? Generics were added to the language without having to do anything special on the programmer's part.Poker
@BradleyUffner generics are were a new compiler concept and those are are new types that live in mscorlib. it would be like using generics in a .net 1.1 project.Paripinnate
@DanielA.White Why not? They added System.FormattableString to mscorlib in .NET 4.6. msdn.microsoft.com/en-us/library/…Gametophore
@dman2306 that would require a new .net version... which requires a user operation to upgrade.Paripinnate
@DanielA.White Like .NET 4.6.2 that was released like 3 weeks ago and very easily could have had it?Gametophore
@dman2306 once again, unless you have release notes that state that they did include it, your what ifs are completely irrelevant and, even worse, misleading.Apulia
sure but thats up to them to decide. 4.6.2 likely was a bug fix release.Paripinnate
@DavidL it's simple, because EVERY other C# feature has NEVER required a Nuget package. So let me reverse your question; why on Earth would anyone expect this single language feature to require a NuGet package when no other additions ever have including other additions in C#7?Gametophore
@dman2306 here's a relevant issue: github.com/dotnet/roslyn/issues/13177Paripinnate
@dman2306 I expect nothing other than what is in the release notes. So once again, if the behavior was present in RC and nothing was seen to the contrary in RTM release notes, this is NOT the appropriate forum! If you are concerned about it, you should be making bug/feature requests on ASP.NET. Keep in mind, part of the new .NET mantra is pay to play, pulling in what you need as you need it. This could become a more common pattern going forward. That said, it would appear that they intend to migrate it into mscorlib, which once again points to release notes as the source of truth :).Apulia
I think part of the problem is that all the "What's new in C# 7.0" articles that have been circulating for the past year talk about the new tuple syntax as being part of the C# 7 language, and not just a library that C# 7 can use. I sort of expected the new tuple features to be "syntactic sugar" at the compiler level. I understand that I was wrong about that, and I'm not really upset, but there is a lot of confusion out there over this feature.Poker
@DavidL You seem really upset about this. Someone asked a question because of confusion with a new language feature that was released less than 24 hours ago. No one is attacking you, no one is attacking Microsoft. Someone is just trying to get clarification on something that seems confusing. I believe SO is very much a forum for a question such as "Is there a way to have tuple syntax enabled for every project by default?" The answer may be "No", but that doesn't mean it's a bad question to ask. I guarantee you in a month you'll look back and see many people referencing this question.Gametophore
@dman2306 I understand what you're saying and I apologize if anything came off as being taken personally or what could have been construed as a personal attack on others. No, the question itself is perfectly fine, it is the comments discussion that is misleading. My entire point is that Microsoft SHOULD port this to mscorlib and we should encourage them to do so and that tracking issues and release notes is the best way to understand the current state of non-included language features.Apulia
@DavidL By the way, I should also add (I will attack MS), shame on them for the release notes. They still reference github.com/dotnet/roslyn/blob/master/docs/features/patterns.md which says that * is used for discards which was dismissed months ago in favor of _. Some of the specs referenced in the release notes are very out of date and just plain wrong.Gametophore
@dman2306 feel free to send them PR to fix them upParipinnate
@DanielA.White I would except on the csharplang repo, they seem to indicate they already have new versions, they're just not published yet...Gametophore
Anyway, for the opening question, nuget packages will start using it and, especially in .net standard where dependencies are transitive, this means soon all project will have support for valuetuple as much as most of them now have some async/await code.Plantaineater
@dman2306 "EVERY other C# feature has NEVER required a Nuget package"... Well, actually, dynamic is a C# keyword, but if you want to use it you need to import a Reference of the Microsoft.CSharp dll... it is not present by default.Fulford
P
25

According to https://github.com/dotnet/roslyn/issues/13177, the ITuple and ValueTuple types will be added to mscorlib in "the first version after" .NET Framework 4.7. According to the .NET Framework 4.7 release notes, it has been added. Adding it to 4.6.x would break semver. Hence they provided the types as a Nuget package so that projects based on older framework versions can use it.

This is akin to a .NET 2.0 project wanting to use LINQ which the extension methods lived in System.Core, not mscorlib.

One option you could do is create your own project templates in the interim that reference the NuGet package.

Paripinnate answered 7/3, 2017 at 21:2 Comment(5)
github.com/dotnet/roslyn/issues/14970 and github.com/dotnet/roslyn/pull/15177 seems to indicate it should suggest you install the NuGet package when you get this error. However I don't get anything like this. Not sure about anyone else?Gametophore
@dman2306 maybe there was a problem with it and they had to pull it out.Paripinnate
@GrantWinney im guessing it would be smart to refresh the nuget references at that point. from there i would suspect the package would be pretty empty. maybe just some type forwarding info.Paripinnate
@GrantWinney Does anyone recall what it did when they first introduced async and await as the NuGet package Microsoft.Bcl.Async before it officially shipped if you still had that referenced after it was added to the BCL? My guess would be we'd get the same behavior as what that did. Just a guess of course...Gametophore
Microsoft.Bcl.Async forwarded all of its calls to the framework versions if you where running in a .NET 4.5 environment.Welch

© 2022 - 2024 — McMap. All rights reserved.