Why compiling csc compiling C # 7 after installing VS 2017?

I just downloaded Visual Studio 2017 RC, which was released a few days ago and comes with C # 7 support. I can use C # 7 functions from the IDE:

However, this behavior does not seem to be true for the command line. I am working on a project that requires the csc handle C # 7 and above. However, when I try to go to the same directory as the project and compile 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 it looks like the csc version found in my PATH does not support C # 7. I did a little research and found a similar question for C # 6, which suggested checking that you call 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 directory is selected from the MSBuild\14.0\Bin directory, and not the old one in v4.0.30319 . I also ran csc /version , which tells me that the csc version is 1.3.1.60616, which really only supports C # 6.

Does anyone know how to enable C # 7 features for the csc version on the command line? Thanks!

+5
source share
2 answers

You need to run the "Developer Command Line for VS 2017 RC". Then you will see that csc.exe will have version number 2.0.

It is well known that for each new version of VS you should use your dedicated prompt with the corresponding environment variables loaded.

+6
source

You can run "where csc.exe" from the visual studio 2017 command line and export the csc version you need by adding it to the Path system variable. I was in a similar case when I needed to compile through the command line and I finished the installation

 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\ 

in the system way.

0
source

Source: https://habr.com/ru/post/1260399/


All Articles