将 C# 7.1 与 MSBuild 结合使用

Using C# 7.1 with MSBuild(将 C# 7.1 与 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 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

MSBuild cannot find a reference(MSBuild 找不到参考)
The reference assemblies for framework .NETCore, Version=v5.0 were not found(未找到框架 .NETCore,Version=v5.0 的参考程序集)
quot;File has a different computed hash than specified in manifestquot; error when signing the EXE(“文件的计算哈希值与清单中指定的不同签署EXE时出错)
Good-practices: How to reuse .csproj and .sln files to create your MSBuild script for CI?(良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 MSBuild 脚本?)
Run an MSBuild target only if project is actually built(仅在实际构建项目时运行 MSBuild 目标)
MS-Build BeforeBuild not firing(MS-Build BeforeBuild 未触发)