5

I'm trying to test some C#7 features as outlined in this blog.

https://joshvarty.wordpress.com/2016/02/10/lrn-quick-tip-how-to-test-out-c-7-features-with-roslyn/

I've followed the steps many times and I've got the projects to build and open a new instance of Visual Studio. Once I open the instance, I'm then creating a new console project from the file menu. When I attempt to use the Tuples I get the following error.

   Error CS0518 Predefined type 'System.ValueTuple`2' is not defined or imported

I'm not sure if I'm doing something wrong? I'm feeling like there's one tweak that's missing.

Auguste
  • 2,007
  • 2
  • 17
  • 25
rid00z
  • 1,566
  • 3
  • 16
  • 35
  • Possible duplicate of [Predefined type 'System.ValueTuple´2´ is not defined or imported](https://stackoverflow.com/questions/38382971/predefined-type-system-valuetuple%c2%b42%c2%b4-is-not-defined-or-imported) – Wai Ha Lee Feb 26 '19 at 16:55

3 Answers3

8

Install the "System.ValueTuple" NuGet package: https://www.nuget.org/packages/System.ValueTuple/

amartynov
  • 4,125
  • 2
  • 31
  • 35
4

I solved this issue by manually including the System.ValueTuple class from the roslyn github repository

Rob
  • 26,989
  • 16
  • 82
  • 98
rid00z
  • 1,566
  • 3
  • 16
  • 35
2

In Visual Studio Menu;
Tools => NuGet Package Manager => Package Manager Console

Type:
Install-Package System.ValueTuple

e.g.:

(string Name, int Number) LookupName() // tuple return type
{
    return ("Siya", 16); // tuple literal
}

// In the caller:
var res = LookupName();
var resText = $"Name: {res.Name}, Number: {res.Number}";

Debug.WriteLine(resText);
Siyavash Hamdi
  • 2,764
  • 2
  • 21
  • 32