Everett Glovier
Everett Glovier

Reputation: 328

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. I added a windows platform and tried to build and get the following error:

Could not find 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. I tried installing WinJS with npm and that didn't work. I have no idea what to do. Any ideas?

Upvotes: 7

Views: 7767

Answers (4)

Vijay Sasavadiya
Vijay Sasavadiya

Reputation: 1

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.

and if i does not put that line in config.xml then it throws an error as given above.

Upvotes: 0

Cedric Reichenbach
Cedric Reichenbach

Reputation: 9319

The HTML/JS-Apps part of the Windows (Phone) 8.1 SDK is missing. As described in this answer, you can install it as follows:

  • In Visual Studio, click "File" -> "New Project"
  • Select "Windows 8"
  • Double-click "Install Windows 8.1 and Windows Phone 8.0/8.1 tools"

Upvotes: 5

raider33
raider33

Reputation: 1673

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. When adding Windows as a platform, I tried:

cordova platform add windows
cordova build windows

The build step failed with the same error as above:

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 could not run either of the 8.1 projects, even after I tried installing the 8.1 SDKs. However, it had no issue running the Windows 10 Universal project, which packaged its own version of WinJS not dependent on an SDK.

You can change Cordova to target Windows 10 by adding the following line to the config.xml

<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.

Upvotes: 5

Pavel Durov
Pavel Durov

Reputation: 1297

What type of windows project are you trying to build? 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. Set a break point there and walk through it..

Once I needed to change the appVersion in order to load the right script.

//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();
} 

Upvotes: 0

Related Questions