问题描述
我在解决方案中有几个项目,C# 7 功能(例如元组和 throw 表达式)在所有库项目中都可以正常工作,但是有一个(非核心)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="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')" />
更新:我尝试使用 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 版本,必须选中包管理器顶部的包含预发布"复选框.安装后,Language version
高级设置不必从 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 项目中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!