我刚刚开始在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:
更多推荐
在ASP.NET应用程序中启用C#7
发布评论