【问题标题】:UWP project failed on GitHub Actions because certificate is invalid APPX0107UWP 项目在 GitHub Actions 上失败,因为证书无效 APPX0107
【发布时间】:2020-03-24 08:42:07
【问题描述】:

ITNOA

我在 GitHub 中有一个项目,在 here 中有 UWP 项目。

我想使用this main.yml configuration为此项目设置 GitHub Actions

当 GitHub Actions 想要使用以下命令构建我的解决方案时

- name: Library build

  run: |

    cd src

    nuget restore

    msbuild PCLAppConfig.sln /verbosity:normal /t:Rebuild /p:Configuration=Release

我在 UWP 构建中看到失败错误并出现以下错误

2020-03-23T13:07:20.1871936Z "D:\a\PCLAppConfig\PCLAppConfig\src\PCLAppConfig.sln" (Rebuild target) (1) ->
2020-03-23T13:07:20.1872322Z "D:\a\PCLAppConfig\PCLAppConfig\src\DemoApp\DemoApp.UWP\DemoApp.UWP.csproj" (Rebuild target) (10) ->
2020-03-23T13:07:20.1872524Z (_GenerateCurrentProjectAppxManifest target) -> 
2020-03-23T13:07:20.1872807Z   C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\AppxPackage\Microsoft.AppXPackage.Targets(2650,5): warning APPX0107: The certificate specified is not valid for signing. For more information about valid certificates, see http://go.microsoft.com/fwlink/?LinkID=241478. [D:\a\PCLAppConfig\PCLAppConfig\src\DemoApp\DemoApp.UWP\DemoApp.UWP.csproj]
2020-03-23T13:07:20.1873172Z 
2020-03-23T13:07:20.1873447Z 
2020-03-23T13:07:20.1873657Z "D:\a\PCLAppConfig\PCLAppConfig\src\PCLAppConfig.sln" (Rebuild target) (1) ->
2020-03-23T13:07:20.1873802Z "D:\a\PCLAppConfig\PCLAppConfig\src\DemoApp\DemoApp.UWP\DemoApp.UWP.csproj" (Rebuild target) (10) ->
2020-03-23T13:07:20.1873935Z (_GenerateAppxPackageFile target) -> 
2020-03-23T13:07:20.1874153Z   C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\AppxPackage\Microsoft.AppXPackage.Targets(3402,5): error APPX0107: The certificate specified is not valid for signing. For more information about valid certificates, see http://go.microsoft.com/fwlink/?LinkID=241478. [D:\a\PCLAppConfig\PCLAppConfig\src\DemoApp\DemoApp.UWP\DemoApp.UWP.csproj]
2020-03-23T13:07:20.1874919Z 
2020-03-23T13:07:20.1875022Z     4 Warning(s)
2020-03-23T13:07:20.1875125Z     1 Error(s)
2020-03-23T13:07:20.1875697Z 
2020-03-23T13:07:20.1875988Z Time Elapsed 00:03:28.50
2020-03-23T13:07:20.6575030Z ##[error]Process completed with exit code 1.

注意如果我在本地计算机上运行msbuild PCLAppConfig.sln /verbosity:normal /t:Rebuild /p:Configuration=Release,构建成功并且没有任何错误,我可以在本地运行UWP应用程序。

我的问题是我的问题是什么?我该如何解决这个问题?

谢谢

【问题讨论】:

  • 我不确定,但*.com/q/60492910/1539100 是否可能与我的错误有关?我的错误代码不同
  • 您确定您在 UWP 应用中的证书仍然有效吗?打开它并检查日期,也许您需要生成新的证书。而且自签名证书对侧载应用无效,如果您制作的软件包不是用于 win 商店,则需要代码签名证书。
  • 是的,我确定,因为在这个问题之前,msbuild 说过期证书错误,我更新证书并解决了这个问题,我再次说这个项目完全在我的 PC 中构建,在 PowerShell 上没有任何错误。感谢回复
  • 请检查您的github repos是否包含pfx证书文件,一般上传解决方案时会忽略pfx文件。

标签: uwp msbuild github-actions building-github-actions


【解决方案1】:

您应该设置 PackageCertificateKeyFile 并确保将文件推送到 GitHub。您应该将密码添加到您的 pfx 文件中。

    /p:PackageCertificateKeyFile=Package_TemporaryKey.pfx /p:PackageCertificatePassword="123"

请替换Package_TemporaryKey.pfx和密码。

如果您不想将 pfx 文件推送到 GitHub 可以使用github secrets

首先是将pfx文件解析为base64字符串。

第二个是将pfx文件base64字符串设置为github secrets。

然后你可以在开始构建之前使用这个 base64 字符串。

Decode the Base64 encoded Pfx
- name: Decode the Pfx
  run: |
    $pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}")
    $currentDirectory = Get-Location
    $certificatePath = Join-Path -Path $currentDirectory -ChildPath $env:Wap_Project_Directory -AdditionalChildPath $env:SigningCertificate
    [IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)

你可以在github找到我的示例代码

编辑

我阅读了您的代码并找到了 DemoApp.UWP_TemporaryKey.pfxWindows_TemporaryKey.pfx 文件。因为我的网速很差,你能不能通过git clean -xdf清理你的代码,然后用命令行在本地编译?也许您应该明确指定要使用的文件。

【讨论】:

  • 非常感谢您的回复,我可以在 msbuild 中自动使用您的命令吗? (例如在 csproj 或 sln 文件中写一些东西?)或者我必须在脚本文件中写命令?
  • @sorosh_sabz 请试试,我自己没试过
  • 我删除了 Windows_TemporaryKey.pfx,一切正常,谢谢 :)
最近更新 更多