Electron-builder: Can't create self-signed-cert for appx app

Created on 2 Sep 2017  Â·  12Comments  Â·  Source: electron-userland/electron-builder

Hello,

I'm trying to build appx app with electron-builder 19.27.3 on Windows 10

But faced with issues once tried to self-sign certificate. The certificate itself was generated with Git-Bash in Run as Administrator mode . And manually imported afterwards. But error appears still:

$ electron-builder -w appx

electron-builder 19.27.3
No native production dependencies
Packaging for win32 x64 using electron 1.6.11 to release-builds\win-unpacked
Error: AppX package must be signed, but certificate is not set, please see https://electron.build/code-signing

You can use `electron-builder create-self-signed-cert -p YourName` to create self-signed certificate
    at C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\src\targets\appx.ts:42:13
    at Generator.next (<anonymous>)
$ electron-builder create-self-signed-cert -p certificate

When asked to enter a password ("Create Private Key Password"), please select "None".
C:\Users\Username\code\certificate.pfx created. Please see https://electron.build/code-signing how to use it to sign.
C:\Users\Username\code\certificate.pfx will be imported into Cert:\LocalMachine\TrustedPeople Operation will be succeed only if runned from root. Otherwise import file manually.
Error: powershell.exe exited with code 1
Error output:
Import-PfxCertificate : Missing an argument for parameter 'CertStoreLocation'. Specify a parameter of type
'System.String' and try again.
At line:1 char:98
+ ... name\code\certificate.pfx" -CertStoreLocation
+                                                        ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Import-PfxCertificate], ParameterBindingException
    + FullyQualifiedErrorId : MissingArgument,Microsoft.CertificateServices.Commands.ImportPfxCertificate


    at ChildProcess.childProcess.once.code (C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\node_modules\builder-util\src\util.ts:195:14)
    at Object.onceWrapper (events.js:318:30)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at maybeClose (internal/child_process.js:927:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
From previous event:
    at spawn (C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\node_modules\builder-util\src\util.ts:158:3)
    at C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\src\cli\create-self-signed-cert.ts:33:11
    at Generator.next (<anonymous>)
From previous event:
    at createSelfSignedCert (C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\out\cli\create-self-signed-cert.js:40:21)
    at __dirname.default.command.command.command.command.argv (C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\out\cli\cli.js:151:125)
    at loadEnv.then (C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\out\cli\cli.js:155:79)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5)
From previous event:
    at Object.args [as handler] (C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\out\cli\cli.js:155:68)
    at Object.self.runCommand (C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\node_modules\yargs\lib\command.js:233:22)
    at Object.Yargs.self._parseArgs (C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\node_modules\yargs\yargs.js:990:30)
    at Object.get [as argv] (C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\node_modules\yargs\yargs.js:927:19)
    at Object.<anonymous> (C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\out\cli\cli.js:151:418)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:598:3

Kindly help

Most helpful comment

The issue was on my end. Adding "certificateFile" : "certificate.pfx" to package.json resolved the problem.

"win": {
      "target": [
        "portable",
        "appx"
        ],
      "certificateFile" : "certificate.pfx",
      "icon": "build/icon.ico"
    }

After that appx was built flawlessly.

electron-builder is the most amazing worry-free builder ever!

Thanks @develar!

All 12 comments

You can ignore cert import error. I think cert is created in the your project root. Just use created PFX file. Import file to cert store if need, but it is required only to run, because electron builder doesn't use win cert store.

Thanks for your quick response @develar
Issue here is that I got the error even after importing cert:

$ electron-builder -w appx

electron-builder 19.27.3
No native production dependencies
Packaging for win32 x64 using electron 1.6.11 to release-builds\win-unpacked
Error: AppX package must be signed, but certificate is not set, please see https://electron.build/code-signing

You can use `electron-builder create-self-signed-cert -p YourName` to create self-signed certificate
    at C:\Users\Username\AppData\Roaming\npm\node_modules\electron-builder\src\targets\appx.ts:42:13
    at Generator.next (<anonymous>)

Please read Code Signing docs — link above.

The issue was on my end. Adding "certificateFile" : "certificate.pfx" to package.json resolved the problem.

"win": {
      "target": [
        "portable",
        "appx"
        ],
      "certificateFile" : "certificate.pfx",
      "icon": "build/icon.ico"
    }

After that appx was built flawlessly.

electron-builder is the most amazing worry-free builder ever!

Thanks @develar!

I will improve error message to make clear that you need to set certificateFile or set corresponding env vars.

MS is not Apple — Apple allows you to run unsigned apps, but MS doesn't. And it is bad joke, because on Windows code signing simply doesn't work and doesn't play the same important role as on macOS (where user cannot run unsigned app by default).

Yeah, you are right @develar. I just dived into building the app for Windows Store yesterday and was a bit suprised with many prerequisite steps which need to be taken for building appx So electron-builder was a real cure here.

Quick question trough - is appx app is fine to submit to Windows Store once built with electron-builder or do I need to use MS Desktop Bridge for consistency?

https://docs.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-run-desktop-app-converter

Thanks!

@black-snow Please advice "is appx app is fine to submit to Windows Store once built with electron-builder"

Hey @vasyl-shumskyi

last time I deployed to the Windows Store everything worked just fine. Develar did a great job adding and fixing stuff. That being said I don't know how the current state is - please also take a look at https://github.com/electron-userland/electron-builder/issues/2029
I guess you'll just have to give it a shot and see how it works out ;)

Please, please do report back if you encountered any issues.

@black-snow got it. Will give it a try! Whatever results I get, will keep you guys updated.

I just occasionally noticed #2029 as well and subscribed to it :) Will close this issue since its solved and continue my appx journey in #2029.

The same error in 2020...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omarkilani picture omarkilani  Â·  3Comments

lbssousa picture lbssousa  Â·  3Comments

JohnWeisz picture JohnWeisz  Â·  3Comments

NPellet picture NPellet  Â·  3Comments

popod picture popod  Â·  3Comments