在ASP.NET应用程序中启用C#7

编程入门 行业动态 更新时间:2024-10-22 18:44:13
本文介绍了在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 Web项目中启用c#7.0的方法. 如果我写如下语句:

I cannot find a way to enable c# 7.0 in the asp 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:

  • 卸载Microsoft.CodeDom.Providers.DotNetCompilerPlatform
  • 重新安装
  • 在web.config中, 下:system.codedom > compilers > compiler, 将compilerOptions ="/langversion: 6更改为7
  • Uninstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform
  • Re-install it
  • In web.config, under: system.codedom > compilers > compiler, change compilerOptions="/langversion:6 to 7
  • 更多推荐

    在ASP.NET应用程序中启用C#7

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

    发布评论

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

    >www.elefans.com

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