Cordova build windows on Windows 10 and VisualStudio 2017

烈酒焚心 提交于 2020-01-02 23:01:55

问题


Trying to build the Cordova App on Windows 10 always fails with
(node:31) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): No valid MSBuild was detected for the selected target.
on Windows 10 Pro 1709 with VisualStudio 2017 Community Edition.

I exactly followed all instructions for Windows 10 in the cordova docs for windows

I have installed VS with package Mobile Development with Javascript which includes the cordova tools. I also installed the additional Build Tools for Visual Studio 2017.
To create the test app, I used the commands from the docs:

cordova create test
cd test
cordova platform add windows
cordova build windows

After hours of research, I found out the issue could be an active WindowsPolicy DisableRegistryTools, but this is not causing the issue. Reinstalling VisualStudio does also not have any effect. The error message is always the same.

Edit: I just checked cordova requirements, I did not know that command before. This is the output:

Requirements check results for windows:
Windows OS: installed Windows 10
MSBuild Tools: not installed
MSBuild tools v.12.0 not found. Please install Visual Studio 2013 Express  for Windows Update2 from https://www.visualstudio.com/downloads/download-visual-    studio-vs
Visual Studio: not installed
Required version of Visual Studio not found. Please install Visual Studio 2013 Express for Windows Update2 from     https://www.visualstudio.com/downloads/download-visual-studio-vs
Windows SDK: not installed
Windows SDK not found. Ensure that you have installed Windows 8.1 SDK along with Visual Studio or install Windows 8.1 SDK separately from     https://dev.windows.com/en-us/downloads
Windows Phone SDK: not installed
Windows Phone SDK not found. Ensure that you have installed Windows Phone 8.1 SDK along with Visual Studio or install Windows Phone 8.1 SDK separately from https://dev.windows.com/develop/download-phone-sdk
Error: Some of requirements check failed

If it is possible, I would try the required older version of VisualStudio. But the download is not available anymore.


回答1:


I finally got cordova build windows and cordova run windows working by following this recently posted guide on the cordova blog.

  • Install VistualStudio Community 2017 or better

    • With options:

      • Universal Windows Platform development,
        +add optional: Windows 10 Mobile-Emulator (Fall Creators Update)
        +add optional: Windows 10 SDK (10.0.15063.0) für UWP: C#, VB, JS
        +add optional: Windows 10 SDK (10.0.10586.0)

      • Mobile development with JavaScript
        +add optional: Windows 10 Mobile-Emulator (Fall Creators Update)
        +add optinoal: UWP-Tools for Cordova

  • Install Build Tools for Visual Studio 2017, you will find them on the VS downloads page in Other Tools and Frameworks section

    • The options below might not all be necessary, but I installed them all to get it just running.
    • With options:

      • Visual C++ Buildtools
        +add optional: Windows 10 SDK (10.0.16299.0) für Desktop C++
        +add optional: Visual C++-Tools für CMake

      • Buildtools for web development
        +add optional: Development tools für .NET Framework 4–4.6
        +add optional: .NET Core 2.0-Development tools
        +add optional: NuGet-Ziele und Buildaufgaben
        +add optional: TypeScript 2.6 SDK
        +add optional: Extended ASP.NET-Features

      • .NET Core-Buildtools

      • Node.js Buildtools


  • Make sure to use cordova platform add windows@6.0.0
    otherwise 5.0.0 will be added to your project, which is mostly incompatible to VisualStudio 2017.
  • Make sure to set MSBUILDDIR to C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin
  • Make sure to NOT use bash on Windows, otherwise Cordova will not recognize you are on a Windows operating system. So you have to use CMD or Powershell.
  • I also added these preferences to the config.xml

    <platform name="windows">
        <preference name="windows-target-version" value="10.0" />
        <preference name="windows-phone-target-version" value="10.0" />
        <preference name="WindowsDefaultUriPrefix" value="ms-appx://" />
    </platform>
    

    - If you still run into errors, try opening the project in Visual Studio and build there.

  • If you are using Ionic 3, you can use bash to run npm install, ionic cordova platform add windows@6.0.0 and ionic cordova build windows --prod to compile and copy to platform/www. But building the .appx package must be done with CMD using cordova build windows or cordova run windows

  • If the App style remains Android-like, add this config to app.module.ts

     imports: [
       IonicModule.forRoot(MyApp, {
           mode: 'wp',
       })
     ],
    


来源:https://stackoverflow.com/questions/49141514/cordova-build-windows-on-windows-10-and-visualstudio-2017

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!