简体   繁体   中英

Visual Studio 2017 web project: can't use C#7

I've created a brand new web project in Visual Studio 2017, but I can't use any C#7 features in this web project. No errors are reported in Visual Studio, but the build fails and this is verified by the output window which shows the CSC task failing.

Here is a project which reproduces the issue.

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

It's an out of the box VS web project with the exception of the addition of the following code in HomeController.cs:

var i = 1_000_000;

This uses _ which is a C#7 feature. Remove this line and the build succeeds.

Non-web projects compile fine with C#7 features, and I've tracked down the difference to a different compiler being 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 resolve this?

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

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

For example by Tools->NuGet package Manager -> Package Manager Console

and then type:

Install-Package Microsoft.Net.Compilers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM