简体   繁体   English

Cordova构建Windows错误 - 缺少Microsoft.WinJS.2.0

[英]Cordova Build Windows Error - Missing Microsoft.WinJS.2.0

I've been struggling with this for the past 2 hours. 在过去的两个小时里,我一直在努力解决这个问题。 I have a simple Ionic/Cordova app that I have working on Android and iOS. 我有一个简单的Ionic / Cordova应用程序,我在Android和iOS上工作。 I added a windows platform and tried to build and get the following error: 我添加了一个Windows平台,并尝试构建并获得以下错误:

Could not find SDK "Microsoft.WinJS.2.0" 找不到SDK“Microsoft.WinJS.2.0”

I am using Visual Studio 2015 and am not super familiar, but I attempted to add a reference and it did not work. 我正在使用Visual Studio 2015,并不是非常熟悉,但我尝试添加引用,但它不起作用。 I tried installing WinJS with npm and that didn't work. 我尝试用npm安装WinJS,但是没有用。 I have no idea what to do. 我不知道该怎么做。 Any ideas? 有任何想法吗?

I had the same issue on an app that I'm working on. 我在一个正在处理的应用程序上遇到了同样的问题。 I am using Windows 10 and Visual Studio 2015. My app works fine on iOS / Android. 我正在使用Windows 10和Visual Studio 2015.我的应用程序在iOS / Android上运行良好。 When adding Windows as a platform, I tried: 将Windows添加为平台时,我试过:

cordova platform add windows
cordova build windows

The build step failed with the same error as above: build步骤失败,出现与上面相同的错误:

error MSB3774: Could not find SDK "Microsoft.WinJS.2.0, Version=1.0". 

From Visual Studio, I opened the Solution file and noticed that there are 3 JS projects: one for Windows 8.1, Windows Phone 8.1 and Windows 10.0 Universal. 在Visual Studio中,我打开了解决方案文件,发现有3个JS项目:一个用于Windows 8.1,Windows Phone 8.1和Windows 10.0 Universal。 Visual Studio could not run either of the 8.1 projects, even after I tried installing the 8.1 SDKs. 即使在我尝试安装8.1 SDK之后,Visual Studio也无法运行任何8.1项目。 However, it had no issue running the Windows 10 Universal project, which packaged its own version of WinJS not dependent on an SDK. 但是,运行Windows 10 Universal项目没有任何问题,该项目打包了自己的WinJS版本,不依赖于SDK。

You can change Cordova to target Windows 10 by adding the following line to the config.xml 您可以通过将以下行添加到config.xml来将Cordova更改为目标Windows 10

<preference name="windows-target-version" value="10.0" />

When you run via Cordova, it will install the app locally on your PC, which can be executed like any app from marketplace. 当您通过Cordova运行时,它将在您的PC上本地安装应用程序,可以像市场上的任何应用程序一样执行。

The HTML/JS-Apps part of the Windows (Phone) 8.1 SDK is missing. 缺少Windows(Phone)8.1 SDK的HTML / JS-Apps部分。 As described in this answer , you can install it as follows: 本回答所述 ,您可以按如下方式安装:

  • In Visual Studio, click "File" -> "New Project" 在Visual Studio中,单击“文件” - >“新建项目”
  • Select "Windows 8" 选择“Windows 8”
  • Double-click "Install Windows 8.1 and Windows Phone 8.0/8.1 tools" 双击“安装Windows 8.1和Windows Phone 8.0 / 8.1工具”

What type of windows project are you trying to build? 您正在尝试构建哪种类型的Windows项目? Windows Phone, Universal App, ...? Windows Phone,Universal App,......?

You can check the cordova.js script at line 1317 - there is a logic which identifies what WinJS script to load based on the navigator.appVersion . 您可以在第1317行查看cordova.js脚本 - 有一个逻辑可以根据navigator.appVersion标识要加载的WinJS脚本。 Set a break point there and walk through it.. 在那里设置一个断点,然后穿过它。

Once I needed to change the appVersion in order to load the right script. 一旦我需要更改appVersion以加载正确的脚本。

//Cordova code, line [1317]:
 if (!window.WinJS) {
    var scriptElem = document.createElement("script");

    if (navigator.appVersion.indexOf('MSAppHost/3.0') !== -1) {
        // Windows 10 UWP
        scriptElem.src = '/WinJS/js/base.js';
    } else if (navigator.appVersion.indexOf("Windows Phone 8.1;") !== -1) {
        // windows phone 8.1 + Mobile IE 11
        scriptElem.src = "//Microsoft.Phone.WinJS.2.1/js/base.js";
    } else if (navigator.appVersion.indexOf("MSAppHost/2.0;") !== -1) {
        // windows 8.1 + IE 11
        scriptElem.src = "//Microsoft.WinJS.2.0/js/base.js";
    } else {
        // windows 8.0 + IE 10
        scriptElem.src = "//Microsoft.WinJS.1.0/js/base.js";
    }
    scriptElem.addEventListener("load", onWinJSReady);
    document.head.appendChild(scriptElem);
}
else {
    onWinJSReady();
} 

My App Also Throw Same Error 我的应用程序也抛出相同的错误

C:\Program Files\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(2049,5):error MSB3774: Could not find SDK "Microsoft.WinJS.2.0, Version=1.0 [E:\winTest\myApp\platforms\windows\CordovaApp.Windows.jsproj]

if i try <preference name="windows-target-version" value="10.0" /> then it build successfully but the app was unable to install in device. 如果我尝试<preference name="windows-target-version" value="10.0" />然后它成功构建但应用程序无法安装在设备中。

and if i does not put that line in config.xml then it throws an error as given above. 如果我没有在config.xml中放置该行,那么它会抛出上面给出的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM