如何同步VS2019中后台编译器与网站构建编译器的版本?
问题描述
环境信息
- 使用VS2019 IDE,解决方案包含多个类库项目和一个本地IIS托管网站(无csproj文件,在解决方案资源管理器中显示为
http://localhost/websitename/) - 所有项目目标框架均为.NET Framework 4.7.2
- 网站已安装
Microsoft.CodeDom.Providers.DotNetCompilerPlatform.3.6.0NuGet包
编译行为不一致现象
情况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
相关产品推荐
相关产品推荐

