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

查看:84
本文介绍了在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?

更新 这是一个网络项目可用的 Compile 选项的屏幕截图(它是意大利语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 > compilers > compiler, 将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天全站免登陆