2

I create a new 'web site' in Visual Studio 2017.

I'm trying to use the new Tuple syntax - I enter this directly into the code behind:

private (string a, string b) myfunc()
{

}

It says you can't use the new tuple syntax in C# 5. I set this app as .net Framework 4.7

Is it possible to set website apps as C# 7? This works fine in new MVC apps but not websites.

I can't find a clear way to set the C# version in Google. Seems bizarre this isn't easier to set?!

Is using tuples / C# 7 in a web site project possible?

niico
  • 11,206
  • 23
  • 78
  • 161
  • @hvd I don't think this is an exact duplicate because the question here is why are tuples not working in this specific situation. The title implies just setting C# 7 as language version, but there is more to it than just that in the body of the question. – AaronLS May 23 '17 at 12:55
  • 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 Jul 04 '17 at 10:20

1 Answers1

0

Tuples aren't included to C# 7 by default. You need to install System.ValueTuple nuget.

Please see from this blog:

First things first, if you create a new Visual Studio 2017 Console App in .NET Core to try tuples in C# 7, one must first add System.ValueTuple from Nuget to experience the new enhancements.

Alexan
  • 8,165
  • 14
  • 74
  • 101
  • 1
    This is wrong. The NuGet package is not required when .NET 4.7 is used, as .NET 4.7 already includes `ValueTuple`. –  May 15 '17 at 21:42
  • @hvd, if it's included, why he is getting this error? – Alexan May 15 '17 at 21:51
  • The OP isn't getting the error that `ValueTuple` is missing, the OP is getting the error that C# 7 isn't enabled. Read the question, and the answers to the question this is a duplicate of. –  May 15 '17 at 22:00
  • I had actually seen that question - sorry forgot to reference it. it has no accepted answers. I tried the "Uninstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform" - it wasn't installed, in installed it and it does reference language version 7. Still doesn't work. I'm already using version 2.0 compiler, I can't find the "Advanced Build Settings" dialogue - is not available in a website app - but is in an MVC app so I don't have that option. – niico May 15 '17 at 22:30
  • @niico, but did you try ValueTuple nuget? – Alexan May 16 '17 at 02:24
  • @Alex Yes I tried it - no effect and it's in 4.7 anyway which I am also using. – niico May 16 '17 at 08:01
  • @niico In that case, please edit your question to include what you tried, and what happened instead. Be specific: for instance, if it still doesn't work but now fails with a different error, copy the error message. With that extra info, it's possible that your question should be reopened. –  May 16 '17 at 18:47