You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何同步VS2019中后台编译器与网站构建编译器的版本?

问题描述

环境信息

  • 使用VS2019 IDE,解决方案包含多个类库项目和一个本地IIS托管网站(无csproj文件,在解决方案资源管理器中显示为http://localhost/websitename/)
  • 所有项目目标框架均为.NET Framework 4.7.2
  • 网站已安装Microsoft.CodeDom.Providers.DotNetCompilerPlatform.3.6.0 NuGet包

编译行为不一致现象

情况1:使用简化new运算符

示例代码:StringBuilder sb = new();

  • 类库编译正常
  • 网站后台编译器无报错
  • 构建网站时触发以下错误:

    CS8124: Tuple must contain at least two elements.
    CS1526: A new expression requires (), [], or {} after type

情况2:使用传统new写法

示例代码:StringBuilder sb = new StringBuilder();

  • 网站构建正常
  • 后台编译器提示警告:

    IDE0090 'new' expression can be simplified

现有配置

类库项目(csproj文件)

所有类库的csproj文件均包含以下配置:

<LangVersion>latest</LangVersion>

网站项目(web.config)

网站的web.config中包含以下编译器配置:

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

疑问

请问我遗漏了什么配置?另外,我不需要最新语言特性,只要后台编译器与构建编译器的编译行为一致即可。


内容的提问来源于stack exchange,提问作者trw

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 15:20:41