C#7功能在Visual Studio 2017 RC上的Web项目中不起作用

编程入门 行业动态 更新时间:2024-10-22 10:43:49
本文介绍了C#7功能在Visual Studio 2017 RC上的Web项目中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在解决方案中有几个项目,而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项目中不起作用

本文发布于:2023-11-03 15:41:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555473.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中不   功能   项目   Visual   Studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!