YehudaKremer / msix

Create Msix installer for flutter windows-build files.
https://pub.dev/packages/msix
MIT License
276 stars 68 forks source link

[BUG] Cert: can not found driver? #181

Closed lucasjinreal closed 1 year ago

lucasjinreal commented 1 year ago
packing msix files...

Unhandled exception:
dir : 找不到驱动器。名为“Cert”的驱动器不存在。

it says can not found dirver, I didn't know any about dirver? I have installed my own pfx file on my PC

YehudaKremer commented 1 year ago

Please use the bug report template: https://github.com/YehudaKremer/msix/blob/main/.github/ISSUE_TEMPLATE/bug_report.md

caiohamamura commented 1 year ago

I get the same problem, it is not driver issue, it is complaining about the drive when trying to locate the certificates under Cert:\

Here goes the verbose log:

[     0.012s] parsing cli arguments
[     0.084s] validating config values
[     0.088s] running "flutter build windows"...
[     7.902s] building msix files...
[     7.904s] validating build files
[     7.915s] cleaning temporary files
[     7.925s] create app icons
[     7.927s] generating icons
[    17.135s] copying VC libraries
[    17.165s] getting certificate publisher
[    17.166s] getting certificate "Subject" by file certificate
[    17.447s] generate appx manifest
[    17.453s] generate package resource indexing files
[    17.557s] packing msix files...
[    17.558s] packing
[    18.813s] cleaning temporary files
[    19.124s]
Unhandled exception:
dir : NÆo ‚ poss¡vel localizar a unidade. NÆo existe uma unidade com o nome 'Cert'.
No linha:1 caractere:1
+ dir Cert:\CurrentUser\Root | Where-Object { $_.Subject -eq  'CN=Msix  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Cert:String) [Get-ChildItem], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

#0      ProcessResultExtensions.exitOnError (package:msix/src/method_extensions.dart:61:7)
#1      SignTool.installCertificate (package:msix/src/sign_tool.dart:156:13)
<asynchronous suspension>
#2      Msix._packMsixFiles (package:msix/msix.dart:134:9)
<asynchronous suspension>
#3      Msix._createMsix (package:msix/msix.dart:99:5)
<asynchronous suspension>
#4      Msix.create (package:msix/msix.dart:57:5)
<asynchronous suspension>
#5      main (file:///C:/Users/caioh/AppData/Local/Pub/Cache/hosted/pub.dev/msix-3.13.2/bin/create.dart:4:3)
<asynchronous suspension>

For what I understand the problem is with dir Cert:CurrentUser\Root, this is only a valid command in powershell, if you run that in a cmd you will get the same error. That's why powershell tells you to avoid aliases, maybe if you use Get-ChildItem instead it will work?

caiohamamura commented 1 year ago

I think I get it, it is because I've installed the Powershell Core v7. So that may have messed up with the original PSModulePath that the regular Powershell also uses. If I change powershell.exe to pwsh.exe and add a -Command argument before the actual command in: https://github.com/YehudaKremer/msix/blob/ab1d4b24dba477265fec2f0a48ee4c00b3d316b5/lib/src/sign_tool.dart#L151

Everything works! I don't know how to provide a solution to that issue tough, since it is not everybody who has the pwsh.exe installed.

caiohamamura commented 1 year ago

Okay, now I kind of get it. The only way to reproduce this problem is to run the command from inside the pwsh.exe itself, then it will mix up what Modules to load because the pwsh.exe will inject its modules directories inside $env:PSModulePath, so when we call powershell.exe from inside, it will try to load the Powershell Core modules and the problem will arise.

A way to hack around it would be to reread the $env:PSModulePath from the registry before running the dir Cert:\.

We could replace the: https://github.com/YehudaKremer/msix/blob/ab1d4b24dba477265fec2f0a48ee4c00b3d316b5/lib/src/sign_tool.dart#L154

With:

      "\$env:PSModulePath = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine');dir Cert:\\CurrentUser\\Root | Where-Object { \$_.Subject -eq  '${_config.publisher}'}"
YehudaKremer commented 1 year ago

Hello

@caiohamamura thanks you for research and the PR fix 👍 i publish new version 3.13.3 with the fix.