1

I have recently upgraded my Cordova solution to work with Visual Studio 2017. I am able to successfully build Android APKs from within the Visual Studio Professional 2017 IDE.

When I try to build the solution using MSBuild 2017 from the command line, I receive the following error:

MSBUILD : cordova-build error BLDErr_Build_ExceptionLookingForNode: Unable to determine location of Node.js installation. Exception: Could not load file or assembly 'Microsoft.VisualStudio.Setup.Engine, Version=1.0.0.0, Culture=neutral, Pu blicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. [C:\dev\Common\Source\Mobile-NGC\PhalanxNGC.jsproj]

I have tried it when using Node.js v4.8.4 and v6.11.3, as well as 32-bit and 64-bit versions but with no success.

I have also looked for the Microsoft.VisualStudio.Setup.Engine.dll and I can find it in the IDE directory: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Setup.Engine.dll

I am unable to find it under the MSBuild directory.

Any help would be appreciated. Thanks.

Edit: To clarify, the MSBuild I am using is the "Build Tools for Visual Studio 2017" downloaded from https://www.visualstudio.com/downloads/.

It is installed in C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin

The MSBuild command I am using is:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBUILD.exe /nologo /p:Configuration=Debug /verbosity:diag C:\dev\Common\Source\Mobile-NGC\NGC.sln

Edit2: After comparing the failing MSBuild CLI output with the successful IDE build output, I can see that the property NodeJsDir is not logged for the failed CLI MSBuild.

This is the line from the successful build log: NodeJsDir = C:\ProgramData\Microsoft\VisualStudio\MDA\8430d60a\taco-toolset-6.3.1

Edit3: It looks as though other Environment Variables for Tools for Apache Cordova are missing from the failing build log. These include: NODEJSDIR, NPMINSTALLDIR, LANGNAME, BUILDVERBOSITY, GIT_HOME.

Update: I have reported this to Microsoft support and it is now logged as an issue. The work around for now is to build using devenv from the command line:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.com [PathToCordovaSolution] "Debug|Android"

Callum
  • 11
  • 4
  • What do you mean "MSBuild 2017"? Is Developer Command Prompt for VS 2017 tool or call MSBuild.exe from C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin? Would you mind sharing me your build command? You can try to create a new blank cordova project, copy scripts to the new project, then check if it works fine. – Leo Liu Sep 27 '17 at 07:23
  • It is the MSBuild from: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin I downloaded it from https://www.visualstudio.com/downloads/ "Build Tools for Visual Studio 2017" – Callum Sep 27 '17 at 08:32
  • thanks for your reply. Since you have installed Visual Studio Professional 2017 on your machine, please try to use MSBuild from: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin. Check if it works fine. If not, please share the build log here. – Leo Liu Sep 27 '17 at 08:39
  • Thanks Leo. I am still receiving the same problem when using the MSBuild from Visual Studio Professional 2017 from the command line. I have saved the output log to here: https://gist.github.com/callum-spartan/7d84461698a52336fc2d732d8eda6db6 – Callum Sep 27 '17 at 09:10
  • I've noticed that the log shows it is still using the other MSBuild.exe: MSBUILDDIR = C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin MSBUILDEXE = C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBUILD.exe – Callum Sep 27 '17 at 09:34
  • The CLI build also fails for a new blank Hello World Cordova App. I've saved the log output here: https://gist.github.com/callum-spartan/9dc2298233f8798868fbacc8d60f61e4 – Callum Sep 27 '17 at 09:47
  • I noticed that it is still using the other MSBuild.exe in your new blank cordova app. It may cause this issue. – Leo Liu Sep 27 '17 at 10:14
  • I have uninstalled the standalone MSBuild from the "Build Tools for Visual Studio 2017" to try and stop it from being used. I can see now that the MSBUILDDIR and MSBUILDEXE are falling back to MSBuild 14. https://gist.github.com/callum-spartan/a8d30fd3a8eaf728d8db458c76223832. – Callum Sep 27 '17 at 10:42
  • The logs do say 'Building with tools version "15.0"' so I don't think it is using those parameters for MSBuild 14. – Callum Sep 27 '17 at 10:50

2 Answers2

0

The only change to you build script is to manually provide MSBuild Property which indicate Visual Studio 2017 Instance using /p:InstanceId=432dc062

This instance id will change after VS2017 updates, so you should manually update build scripts after that.

You current instance could be obtained using vswhere.exe by running

C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe
codevision
  • 5,165
  • 38
  • 50
  • Thanks for your response. I am in correspondence with Microsoft Support and it is now logged as a known issue. I'll update my question with a temporary work around. – Callum Dec 18 '17 at 11:35
  • I also put workaround on Developer community website https://developercommunity.visualstudio.com/content/problem/155613/build-new-cordova-project-with-msbuild-results-in.html So maybe that helps also. – codevision Dec 18 '17 at 13:18
0

The thing which worked for me is go to Tool-> Extension and Updates find 'visual studio tools for Apache cordova' install or enable it again. restart visual studio. and you are back on track