Search code examples
visual-studio-2015msbuildvisual-studio-2019nameof

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


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


Solution

  • 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).