Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova build for Windows with Visual Studio 2017 error

I am having issues with building a new cordova project for Windows.

I have the following versions installed:

  • [email protected], but it can also be reproduced with [email protected]
  • Visual Studio 2017 Enterprise with Tools for Apache Cordova, Windows Mobile Emulator and more.
  • MS Build Tools v14 & v15 installed.

So, to reproduce:

  1. cordova create project1
  2. cd project1
  3. cordova platform add windows
  4. cordova build windows

Then the following error appears: error MSB4019: The imported project "C:\Program Files (86)\MSBuild\Microsoft\VisualStudio\v14.0\JavaScript\Micros oft.VisualStudio.WJProject.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk

When I add the --verbose flag to the build, I notice that the C:\WINDOWS\system32\reg.exe query,HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersions\15.0,/v,MSBuildToolsPath command does not return success, so it uses the Build Tools v14 instead of v15.

If I create a new project with Visual Studio 2017, it compiles & run successfully within Visual Studio, but I have the same errors on cordova build windows command.

I suppose that is the proper registry key were installed, it would work fine. How should I add them properly? Or what is Visual Studio doing that is not being done with the cordova or taco command?

like image 305
Francis Filion Avatar asked May 26 '17 10:05

Francis Filion


1 Answers

Had today the same problem and you pointed me in the right direction - thanks!

The cause for this is, that the cordova build command looks in the registry for the MSBuild path, but since Visual Studio 2017 Microsoft doesn't write the path in the registry anymore (more on this here)

As workaround i created in the registry the following key (don't forget to change the path):

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\15.0]
"MSBuildToolsPath"="C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\MSBuild\\15.0\\Bin\\amd64"

After that the cordova build worked!

Another solution would be just to install VS 2015, but in my case this was not an option, because I use the sqlite plugin in my app and the current version can only be build with VS 2017 for windows.

like image 117
gregor.gretz Avatar answered Nov 09 '22 14:11

gregor.gretz