Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Tuple in VS2017, build failed but show no Error

var range = (first: 1, end: 10);

When I build the project, there is no error in Error List window. but the output window writes:

1>....cs(41,38,41,39): error CS1026: ) expected

1>....cs(41,40,41,41): error CS1001: Identifier expected

1>....cs(41,40,41,41): error CS1002: ; expected

1>....cs(41,41,41,42): error CS1002: ; expected

1>....cs(41,41,41,42): error CS1513: } expected

========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

enter image description here Only when I remove the code var range = (first: 1, end: 10); can this project build success.

By the way, I'm using .NET Framework 4.6.2 (not .Net Core) and I've installed the package System.ValueTuple

like image 833
wtf512 Avatar asked Mar 15 '17 09:03

wtf512


1 Answers

I solved this issue by updating the package Microsoft.Net.Compilers (to version 2.x.x) and changing /langversion in the config file (web.config/app.config) to 7:

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:7 /nowarn:1659;1699;1701" />
    </compilers>
  </system.codedom> 
like image 112
Kjetil Avatar answered Oct 15 '22 01:10

Kjetil