问题描述
使用新的 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 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!