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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With