IronRuby 无法编译使用 'nameof' 运算符的 c# 项目

IronRuby fails to compile c# project which uses 'nameof' operator

我有一个包含很多解决方案的大型 WPF 应用程序,每个解决方案都有很多项目。 IronRuby (v1.0.4) 脚本用于按顺序编译所有项目。

问题陈述:
IronRuby 脚本无法编译使用 'nameof' 运算符的项目,并出现以下错误:

The name 'nameof' does not exist in the current context

我到处搜索,但找不到它不适用于更高版本 Visual studio 的原因。

软件栈:
1. IronRuby 版本:1.0.4
2.网络版本:4.5.2及以上
3.工作VS版本:2015更新3
3.(a) MSBuild 工具版本:14.0

C:\Program Files (x86)\MSBuild.0\Bin>MSBuild.exe -version Microsoft (R) Build Engine version 14.0.27522.0 Copyright (C) Microsoft Corporation. All rights reserved.

14.0.27522.0

3.(b) 从命令提示符编译项目时的消息:

Microsoft (R) Build Engine version 14.0.27522.0
Copyright (C) Microsoft Corporation. All rights reserved.
  1. 非工作 VS 版本:2019 (v16.2.3)
    4.(a) MSBuild工具版本:16.0

C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin>MSBuild.exe -version Microsoft (R) Build Engine version 16.2.37902+b5aaefc9f for .NET Framework Copyright (C) Microsoft Corporation. All rights reserved.

16.2.37902.0

4.(b) 从命令提示符编译项目时的消息:

Microsoft (R) Build Engine version 4.7.3190.0
[Microsoft .NET Framework, version 4.0.30319.42000] Copyright (C) Microsoft
Corporation. All rights reserved.

  1. 两台机器上的 MSBuild 版本给出相同的结果:
C:\Windows\Microsoft.NET\Framework\v4.0.30319>MSBuild.exe -version
Microsoft (R) Build Engine version 4.7.3190.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

4.7.3190.0

将 3(a)、3(b) 与 4(a)、4(b) 进行比较,看起来在更高版本的 VS 构建引擎中存在断开连接,但我无法解决问题阻止我升级到更高的 VS 版本。

感谢任何帮助。

谢谢,
RDV

添加更多详细信息以备不时之需:

查看类似问题 nameof 是 C# 6 特性,它至少需要 VS2015 的构建引擎。(msbuild 14.0)

所以其实msbuild 14.0(for VS2015),msbuild 15.0(for VS2017),msbuild 16.0(for VS2019)都可以编译的很好。 VS2015之后,msbuild是一个单独的build tools package,也不需要安装vs。这样建服务器更方便

C:\Windows\Microsoft.NET\Framework\v4.0.30319>MSBuild.exe

此版本来自.net 4.0 framework,早于msbuild 14.0,不支持C#6特性。

适用于 VS2017 和 VS2019 的 msbuild 路径:C:\Program Files (x86)\Microsoft Visual Studio17 or 2019\build tools or VS version\msbuild.0 or current\bin\msbuild.exe。确保使用正确的 vs 版本并安装必要的工作负载可以帮助避免许多构建问题。希望对大家有帮助。

我的构建 (ruby) 脚本指向一个 compile.rb class,这个 class 有硬编码版本来寻找 VS2015,如果那个版本找不到,那么脚本将使用 v4.0 构建,这就是为什么当我使用 VS 高于 2015 时我总是看到 v4.0。

def path_to_msbuild
    msbuildVS2015path=File.join(ENV['PROGRAMFILES'],"MSBuild/14.0/Bin")
    if File.exist?(msbuildVS2015path)
        File.join(msbuildVS2015path, "/MSbuild.exe /verbosity:quiet")
    else
        versions = ["v4.0.30319", "v3.5", "v2.0.50727"]
        path = File.join(ENV['windir'],"Microsoft.NET/Framework")

修复 "msbuildVS2015path" 后,构建工作正常(我还没有想出一种方法来检查任何已安装的 VS 版本,但出于我的工作目的,我硬编码了 VS2019 版本)。