gpt4 book ai didi

c# - 如何在旧的 ASP.NET 网站(非网站项目)中使用 C# 6.0 或 7.0

转载 作者:行者123 更新时间:2023-12-02 18:20:19 26 4
gpt4 key购买 nike

我有多个旧的 ASP.NET Webforms 网站(这是从头开始创建一个网站的方法): enter image description here

它们不是网站项目。

ASP.NET 网站似乎停留在 C# 5。当尝试使用 C# 6 或 C# 7 的功能时,您会收到错误: enter image description here尝试使用灯泡升级选项失败: enter image description here尝试在 https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version 中找到的任何其他选项由于没有 .csproj 文件,也失败了。或“项目属性”页面中用于更改语言版本的选项。

以下是 ASP.NET 网站上的“生成”选项卡的外观(无“高级”按钮): enter image description here

我安装了 Microsoft.Net.Compilers NuGet 包,但这没有什么区别。

如果可以在 ASP.NET 网站中完成此操作,您有什么想法吗?

最佳答案

如果您安装 Microsoft.CodeDom.Providers.DotNetCompilerPlatform,它将更新您的 web.config 文件以使用当前版本 - 目前为 7.3 :

  <system.codedom>
<compilers>
<compiler extension=".cs" language="c#;cs;csharp" warningLevel="4"
compilerOptions="/langversion:7.3 /nowarn:1659;1699;1701;612;618"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform,
Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<compiler extension=".vb" language="vb;vbs;visualbasic;vbscript" warningLevel="4"
compilerOptions="/langversion:default /nowarn:41008,40000,40008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform,
Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</compilers>
</system.codedom>

关于c# - 如何在旧的 ASP.NET 网站(非网站项目)中使用 C# 6.0 或 7.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56130824/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com