I just downloaded Visual Studio 2017 RC, which was released a few days ago and comes with support for C# 7. I can use C# 7 features from the IDE:
However, this behavior does not seem to hold for the command-line. I am working on a project that requires the csc
executable to handle C# 7 and higher. However, when I try changing to the same directory as the project and compiling the file, I get
> csc Program.cs /target:exe
Microsoft (R) Visual C# Compiler version 1.3.1.60616
Copyright (C) Microsoft Corporation. All rights reserved.
Program.cs(12,23): error CS1026: ) expected
Program.cs(12,25): error CS1001: Identifier expected
Program.cs(12,25): error CS1002: ; expected
Program.cs(12,26): error CS1002: ; expected
Program.cs(12,26): error CS1513: } expected
Program.cs(13,32): error CS1003: Syntax error, '=>' expected
Program.cs(13,32): error CS1525: Invalid expression term '='
So clearly, it looks like the version of csc
found in my PATH does not support C# 7. I did a little research on this and found a similar question for C# 6, which suggested checking to make sure you are invoking the csc
from %PROGRAMFILES(x86)%\MSBuild\14.0\Bin
instead of the old one from C:\Windows\Microsoft.NET\Framework\4.0.30319
, since the latter only supports C# 5. So I did just that:
> where csc
C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe
As you can see the one from the MSBuild\14.0\Bin
directory gets chosen, not the old one in v4.0.30319
. I additionally ran csc /version
which tells me that the version of csc
is 1.3.1.60616, which indeed only supports C# 6.
Does anyone have a clue how to enable C# 7 features for the version of csc
on the command line? Thanks!