I have several projects in the solution, and the C# 7 features, such as tuples and throw expressions, work fine in all of the library projects, but there is a (non Core) web project that doesn't compile due to errors on the C# 7 features. Right after compiling, the error window quickly clears itself, presumably because the IDE/editor compiles the same units without error. I have to use the output window to see the compiler errors. It is as though the IDE/editor are assuming C# 7, but the compiler used in the build is not.
I've tried adding "__DEMO__,__DEMO_EXPERIMENTAL__
" to the conditional compilation symbols, to no avail. I've experimented with targeting different version of the framework and have edited the web.config, including the compilation
and targetFramework
tags of system.web
.
Example errors:
if (!config.Properties.TryGetValue(modelId, out var model)) // error CS1003: Syntax error, ',' expected
if (modelDescription is ComplexTypeModelDescription complexTypeModelDescription) // error CS1026: ) expected
Here are the first few lines of the csproj file for the project:
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..packagesMicrosoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3uildMicrosoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..packagesMicrosoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3uildMicrosoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="..packagesMicrosoft.Net.Compilers.1.3.2uildMicrosoft.Net.Compilers.props" Condition="Exists('..packagesMicrosoft.Net.Compilers.1.3.2uildMicrosoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)Microsoft.Common.props')" />
Update: I tried creating a new web project using the latest template in VS 2017 RC and copying in my source files. Same thing.
I also tried explicitly setting Project | Properties | Build | Advanced | Language Version to 7. Results in "Invalid option '7' for /langversion".
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…