Using C# 7.1 with MSBuild(将 C# 7.1 与 MSBuild 结合使用)
问题描述
使用新的 C# 7.1 语言功能 使用 Visual Studio 2017,您将设置 <LangVersion>latest</LangVersion> 添加到您的项目文件中.
To use the new C# 7.1 language features with Visual Studio 2017, you add the setting <LangVersion>latest</LangVersion> to your project file(s).
但是,从 MSBuild(版本 15.3.409.57025,位于 C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0Bin)构建此类项目会导致一个错误:
However, building such projects from MSBuild (version 15.3.409.57025, located at C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0Bin) results in an error:
CSC : error CS1617: Invalid option 'latest' for /langversion;
must be ISO-1, ISO-2, Default or an integer in range 1 to 6.
MSBuild 尚不支持此功能,还是可以使其正常工作?
Is this feature just not yet supported by MSBuild, or is it possible to get this working?
这涵盖了最初在 Visual Studio 2013 和 2015 中创建的 200 多个项目.它们都使用 Target Framework Migrator 工具(根据检查 .csproj 文件更改,它节省了 很多 次点击并出现 - 以正确完成工作).
This covers 200+ projects that were originally created variously in Visual Studio 2013 and 2015. They were all re-targeted to .NET 4.7 using the Target Framework Migrator tool (which saved lots of clicking and appears - based on inspecting .csproj file changes - to do the job correctly).
所有项目均从 Visual Studio 2017 成功构建.
The projects all build successfully from Visual Studio 2017.
推荐答案
我们发现我们的 MVC 项目触发了这个问题.
We discovered that our MVC projects were triggering this issue.
为了解决这个问题,我们将这些项目使用的 Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet 包从版本 1.0.0 更新到 1.0.7强>.
To fix, we updated the Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package used by these projects from version 1.0.0 to 1.0.7.
这篇关于将 C# 7.1 与 MSBuild 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 C# 7.1 与 MSBuild 结合使用
基础教程推荐
- 从 C# 控制相机设备 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 如果条件可以为空 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
