Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tuples not working in VS 2017

I have a C# library in Visual Studio 2017, and I'm trying to use a tuple in an interface:

IEnumerable<(Guid Id, string name)> GetFoo ();

I have added a reference (via NuGet) to System.ValueTuple.

Visual Studio and ReSharper both do not detect problems with this line, but when I build I get errors:

------ Build started ------ 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Workflow.targets(121,5):
error : Type expected
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Workflow.targets(121,5):
error : Invalid token '(' in class, struct, or interface member
declaration
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Workflow.targets(121,5):
error : Identifier expected; 'string' is a keyword
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Workflow.targets(121,5):
error : ; expected
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Workflow.targets(121,5):
error : Method must have a return type
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This suggests that it is not being compiled using C# 7.

I am targetting .NET Framework 4.6.2.

Things I've tried:

  • Installing the latest updates to Visual Studio
  • Making the project compile using C# 7 explicitly, via Properties > Build > Advanced > Language Version
  • Adding a reference to Microsoft.Net.Compilers

None has had an effect.


Edit: Not a duplicate of C# 7 .NET / CLR / Visual Studio version requirements, as solution there (NuGet package) did not solve issue.

like image 547
Paul Avatar asked Dec 09 '25 21:12

Paul


1 Answers

I think I've worked out the source of the problem.

The project imports:

<Import Project="$(MSBuildToolsPath)\Workflow.Targets" />

Which is the source of the errors in the build output. If I import this into a trivial console project with the above code, I can reproduce the error.

like image 100
Paul Avatar answered Dec 11 '25 12:12

Paul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!