Visual Studio 2017 Web Project: Cannot Use C # 7

I created a completely new web project in Visual Studio 2017, but I cannot use any C # 7 features in this web project. Visual Studio does not report errors, but the build fails, and this is confirmed by the exit window, which indicates that the CSC task is not working.

Here is a project that reproduces the problem.

https://drive.google.com/open?id=0B-mqMIMqm_XHQkxONjRLYzA3SUk

This is a stand-alone VS web project, with the exception of adding the following code to HomeController.cs:

var i = 1_000_000;

In this case, _ is used, which is a C # 7 function. Delete this line and the assembly will succeed.

Non-web projects compile fine with C # 7 features, and I tracked the difference with another compiler used for web projects. Non-web projects use the following compiler:

C: \ Program Files (x86) \ Microsoft Visual Studio \ 2017 \ Enterprise \ MSBuild \ 15.0 \ Bin \ Roslyn \ csc.exe

Web projects use this compiler:

[Path to solution root] \ packages \ Microsoft.Net.Compilers.1.3.2 \ build .. \ tools \ csc.exe

How can i solve this?

+4
source share
1 answer

I tried this on my machine and I had the same problem.

The solution is to install the latest Microsoft.Net.Compilers package.

For example, Tools-> NuGet Package Manager β†’ Package Manager

and then type:

Install-Package Microsoft.Net.Compilers

+7
source

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


All Articles