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

C# 7 features don#39;t work within a web project on Visual Studio 2017 RC(C# 7 功能在 Visual Studio 2017 RC 上的 Web 项目中不起作用)
本文介绍了C# 7 功能在 Visual Studio 2017 RC 上的 Web 项目中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解决方案中有几个项目,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.webcompilationtargetFramework 标签.

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 项目中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)