在 asp.net 应用程序中启用 c# 7 [英] Enabling c# 7 in a asp.net application

查看:94
本文介绍了在 asp.net 应用程序中启用 c# 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始在 Visual Studio 2017 中处理我的旧解决方案.只需在旧 IDE 中打开该解决方案即可无缝运行.c# 应用程序项目现在默认使用 c# 7.0 编译器.这些项目的属性页(编译/高级)可以轻松选择编译器的目标语言版本,默认为最新.

I just started working on my old solution in Visual Studio 2017. Just opening the solution in the old IDE worked seamlessly. The c# application projects now default to the c# 7.0 compiler. The property pages of those project (compilation/advanced) let easily chose the targeted language version of the compiler, defaulting to the latest.

我找不到在 asp.net web 项目 中启用 c# 7.0 的方法.如果我写一个声明,例如:

I cannot find a way to enable c# 7.0 in the asp.net web projects though. If I write a statement such as:

if (int.TryParse("1", out int myInt)) { ... }

IDE 警告我说我需要使用 7+ 版本的语言.

the IDE warns me saying that I need to use version 7+ of the language.

我对这个主题的研究表明,我应该针对 web.config 文件的 system.codedom 编译器区域中的特定 c# 版本,以便针对最新的 Roslyn 版本.

My research on this topic shows I should target the specific c# version in the system.codedom compilers area of the web.config file, so to target the newest Roslyn version.

我现在拥有的是:

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>

哪个针对 c# 6.如果我已经用 nuget 下载了最新的 Roslyn,那么 c# 7 的正确设置是什么?

which targets c# 6. What are the correct settings for c# 7, provided that I have already downloaded the latest Roslyn with nuget?

更新这是一个可用的编译选项的屏幕截图(它是意大利语 VS2017,但应该很容易理解).无法在那里选择目标 c# 版本.

Update Here is a screenshot of the available Compile options for a web project (it is Italian VS2017 but it should be easy to understand). No possibility to select the targeted c# version there.

推荐答案

在网站的 NuGet 窗口中:

In website's NuGet window:

  1. 卸载Microsoft.CodeDom.Providers.DotNetCompilerPlatform
  2. 重新安装
  3. web.config 中,在:system.codedom>编译器编译器,将 compilerOptions="/langversion:6 改为 7
  1. Uninstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform
  2. Re-install it
  3. In web.config, under: system.codedom > compilers > compiler, change compilerOptions="/langversion:6 to 7

这篇关于在 asp.net 应用程序中启用 c# 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆