1
votes

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"

2
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-MSFT
It is the MSBuild from: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin I downloaded it from visualstudio.com/downloads "Build Tools for Visual Studio 2017"Callum
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-MSFT
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: gist.github.com/callum-spartan/7d84461698a52336fc2d732d8eda6db6Callum
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.exeCallum

2 Answers

0
votes

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
0
votes

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