将 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 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)