Renew Windows 10 PFX certificate for Cordova App with Visual Studio

How to renew the PFX certificate for your Windows 10 / 8.1 app created with Tools for Apache Cordova in Visual Studio 2017 / 2015. The certificate is valid for just one year, so it must be renewed to rebuild the app.

Windows 10 Mobile Logo

 

Symptoms

You receive the following error when building your Windows (Tools for Apache Cordova) app from Visual Studio, targeting Windows 10:

Warning APPX0108 The certificate specified has expired. For more information about renewing certificates, see http://go.microsoft.com/fwlink/?LinkID=241478

Cause

The default certificate that Visual Studio generates expires one year after the date on which the certificate was created. If you try to build your app in the Release configuration after that, the build will process will fail.

Renew Certificate using Command Line

Step 1: Use the MakeCert utility to create a self-signed test certificate and private key as follows.

makecert -n "publisher" -r -h 0 -pe -eku "1.3.6.1.5.5.7.3.3,1.3.6.1.4.1.311.10.3.13" -e 12/31/2026 -sv CordovaApp.pvk CordovaApp.cer

replacing publisher with the actual publisher ID that you can retrieve from your app’s Package.StoreAssociation.xml or the publisherId value from build.json. If should begin with “CN=…”.

Step 2: Create a Personal Information Exchange (.pfx) file using Pvk2Pfx.exe with this command:

pvk2pfx -pvk CordovaApp.pvk -spc CordovaApp.cer -pfx CordovaApp.pfx

Step 3: Place the generated CordovaApp.pfx file at the location specified in your packageCertificateKeyFile setting in build.json. Remove and re-add the Windows platform and the new certificate will be installed.

Renew Certificate using Visual Studio 2015

Follow these steps to create a new certificate valid for another year:

Close your Tools for Apache Cordova project from the File > Close Solution menu.

Go to File > Open > Project/Solution. Select the CordovaApp.sln file from the platforms/windows folder and open it:

CordovaApp.sln

CordovaApp.sln is the solution file created by Visual Studio

In the Solution Explorer, you should see a series of solutions for different platforms:

Visual Studio Solution Explorer for Windows 10 and Windows Universal

Visual Studio Solution Explorer

Expand any of them and locate the package.windows.appxmanifest file. Open it by double clicking on it.

Switch to the Packaging tab, locate the Publisher section, and click the Choose Certificate button. A dialog like this will show up:

Visual Studio Choose Certificate

Visual Studio Choose Certificate

From the Configure Certificate drop down, select Create test certificate and enter your certificate’s Publisher Common Name and password:

Visual Studio Create Test Certificate

Visual Studio Create Test Certificate

You should use the same Common Name from your previous certificate. Save this file from the File menu and close it.

For the other platforms

If you have other platforms created, such as Windows 8.1, you can either:

  • Repeat the same process to create new certificates
  • Reuse the PFX certificate you’ve just created in the previous platform

Note: I’m not sure of the implications of reusing the same certificate, but that’s the option I prefer to use and I had no problems with it so far.

After updating all certificates, select File > Save All and close the solution. Now open your Tools for Apache Cordova solution, and run a test build, the certificate error APPX0108 should be gone.

References

The certificate renewal process, along with other options, can also be found in the Renew a Certificate section from the Manage the certificates that Visual Studio uses to sign your app Microsoft Docs article.

 

Disclaimer

The content in this post is for general information purposes only. The information is provided by the author and/or external sources and while we endeavour to keep the information up to date and correct, we make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the website or the information, products, services, or related graphics contained on the post for any purpose. Some of the content and images used in this post may be copyrighted by their respective owners. The use of such materials is intended to be for educational and informational purposes only, and is not intended to infringe on the copyrights of any individuals or entities. If you believe that any content or images used here violate your copyright, please contact us and we will take appropriate measures to remove or attribute the material in question.