Search code examples
cordovawindows-store-appsvisual-studio-2015visual-studio-cordova

How to Override .projitems-files of a Cordova App in Visual Studio 2015


I set up a "Tools for Apache Cordova"-Project in Visual Studio 2015. I have a couple of overrides for the Windows platforms. For that, I placed some appxmanifest-files in the folder res/native/windows. When building the app, those files are copied to the output-directory and used instead of the default ones.

Then I tried the same with the following files:

  • CordovaApp.projitems
  • CordovaAppDebug.projitems
  • CordovaAppRelease.projitems

CordovaApp.projitems is copied and used correctly, just like the appxmanifest files. But it seems like the CordovaAppDebug or the CordovaAppRelease (depending on the build) is not copied and used. Instead it uses some default files.

I actually want to sign my app with another certificate. The certificate is specified in the CordovaAppDebug.projitems and -Release.projitems files. But since the files are never used, VS builds the app with the default certificate.

I already found a workaround, but it is slightly confusing: I can add the certificate settings to the CordovaApp.projitems file. It seems like settings made in that file will override the settings specified in debug or release. The annoying part is, that it still creates and copies the default CordovaApp.pfx - even tho it isn't used.

Some questions:

  • Why are the files CordovaAppDebug.projitems and CordovaAppRelease.projitems not copied and used in the build?
  • How can I work around that issue, so that I can use different configurations based on debug and release?

Solution

  • These files are managed by Cordova itself and cannot be directly modified. However, the way they are generated is via a new feature in recent versions of Cordova.

    What you want to do for the scenario you describe is actually put a build.json file in the root of your project with the following contents:

    {
       "windows": {
         "debug": {
            "packageCertificateKeyFile": "Certificate-Debug.pfx"
         },
         "release": {
            "packageCertificateKeyFile": "Certificate-Release.pfx"
         }
       }
    }
    

    You can also specify the "publisherId" along with the "packageThumbprint" for the certificate file.

    Support for this file has been available for Android for a while and Cordova 5.3.3 actually adds in support for iOS as well.