Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Roslyn future branch cannot use C# 7 feature tuples - Error CS0518 Predefined type 'System.ValueTuple`2

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.

like image 523
rid00z Avatar asked May 10 '16 01:05

rid00z


3 Answers

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

like image 87
amartynov Avatar answered Nov 20 '22 16:11

amartynov


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

like image 38
rid00z Avatar answered Nov 20 '22 15:11

rid00z


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);
like image 36
Siyavash Hamdi Avatar answered Nov 20 '22 15:11

Siyavash Hamdi