1

I have a large WPF application with many solutions and each solution has many projects. IronRuby (v1.0.4) script is used to compile all the projects in order.

Problem Statement:
IronRuby script fails to compile projects which use 'nameof' operator with the following error:

The name 'nameof' does not exist in the current context
  • Failure is seen on machines with Visual Studio 2017 & 2019.
  • Works fine on machines with Visual Studio 2015.
  • If I compile the project individually in VS 20XX, projects are correctly compiled - but that defeats the purpose of having an IR script.

I have searched everywhere but couldn't find the reason it is not working for higher versions of Visual studio.

Software Stack:
1. IronRuby verion: 1.0.4
2. Net version: 4.5.2 and above
3. Working VS version: 2015 update 3
3.(a) MSBuild Tool version: 14.0

C:\Program Files (x86)\MSBuild\14.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) Message while compiling the projects from command prompt:

Microsoft (R) Build Engine version 14.0.27522.0
Copyright (C) Microsoft Corporation. All rights reserved.
  1. Non- working VS version: 2019 (v16.2.3)
    4.(a) MSBuild tool version: 16.0

C:\Program Files (x86)\Microsoft Visual Studio\2019\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) Message while compiling the projects from command prompt:

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 version on both machines give the same result:
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

Comparing 3(a), 3(b) with 4(a), 4(b), looks like there is a disconnect in higher VS version wrt build engine, but I am not able to resolve the issue which is preventing me from going to higher VS version.

Any help is appreciated.

Thanks,
RDV

RDV
  • 957
  • 13
  • 28
  • Finally found ironruby script was pointing to Visual Studio MSBuild version. I fixed it and its working fine now. – RDV Aug 21 '19 at 22:01
  • Hi RDV, you can consider share your discovery and workaround with details as answer and mark it. So the useful info is easier to find by those who need it, just a reminder :) – LoLance Aug 23 '19 at 06:07

2 Answers2

1

To add more details in case anyone else need it:

See similar issue here. nameof is C# 6 feature, it at least needs build engine for VS2015.(msbuild 14.0)

So actually msbuild 14.0(for VS2015), msbuild 15.0(for VS2017), msbuild 16.0(for VS2019) can compile it well. After VS2015, msbuild is a separate build tools package, it doesn't require vs to be installed as well. So it's more convenient for build server.

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

This version is from .net 4.0 framework, is earlier than msbuild 14.0, it doesn't support C#6 feature.

Suitable msbuild path for VS2017 and VS2019 : C:\Program Files (x86)\Microsoft Visual Studio\2017 or 2019\build tools or VS version\msbuild\15.0 or current\bin\msbuild.exe. Make sure use the correct vs version and install the necessary workload can help avoid many build issues. Hope it helps someone.

LoLance
  • 25,666
  • 1
  • 39
  • 73
0

There is a compile.rb class which my build (ruby) script was pointing to, this class had hardcoded version to look for VS2015, if that version is not found, then script would use v4.0 build which is why I would always see v4.0 when I had VS above 2015.

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")

After fixing "msbuildVS2015path", build worked fine (I am yet to figure out a way to check for any installed VS version, but for the purpose of my job, I hard coded VS2019 version).

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
RDV
  • 957
  • 13
  • 28