我在解决方案中有几个项目,而C#7功能(例如元组和throw表达式)在所有库项目中都能正常工作,但是有一个(非Core)Web项目由于以下原因无法编译:C#7功能上的错误.编译后,错误窗口很快就会自动清除,这可能是因为IDE/编辑器可以编译相同的单元而没有错误.我必须使用输出窗口来查看编译器错误.就像IDE/编辑器使用的是C#7,但构建中使用的编译器却没有.
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.
我尝试在条件编译符号上添加" __ DEMO __,__ DEMO_EXPERIMENTAL __ ",但无济于事.我已经尝试过针对不同版本的框架,并编辑了web.config,包括 system.web 的 compilation 和 targetFramework 标记
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.
示例错误:
if (!config.Properties.TryGetValue(modelId, out var model)) // error CS1003: Syntax error, ',' expected if (modelDescription is ComplexTypeModelDescription complexTypeModelDescription) // error CS1026: ) expected以下是该项目的csproj文件的前几行:
Here are the first few lines of the csproj file for the project:
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="schemas.microsoft/developer/msbuild/2003"> <Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" /> <Import Project="..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />更新:我尝试使用VS 2017 RC中的最新模板创建一个新的Web项目,并复制到我的源文件中.一样.
Update: I tried creating a new web project using the latest template in VS 2017 RC and copying in my source files. Same thing.
我还尝试过显式设置Project |属性|建立进阶|语言版本为7.导致"/langversion的无效选项'7'".
I also tried explicitly setting Project | Properties | Build | Advanced | Language Version to 7. Results in "Invalid option '7' for /langversion".
推荐答案解决方案是将Microsoft.Net.Compilers nuget软件包更新为> = 2.0.0.到目前为止,要显示2.0.0版本,必须选中程序包管理器顶部的包括预发行版本"复选框.安装此程序后,不必从 Default 覆盖语言版本高级设置.
The solution is to update the Microsoft.Net.Compilers nuget package to >=2.0.0. As of now, for the 2.0.0 version to appear, the "Include prerelease" checkbox at the top of the package manager must be checked. With this installed, the Language version advanced setting doesn't have to be overridden from Default.
更多推荐
C#7功能在Visual Studio 2017 RC上的Web项目中不起作用
发布评论