2014年11月29日 星期六

Windows Store App Jenkins Error APPX0105、APPX0102、APPX0107

如果是比較窮的開發者,通常會使用 Jenkins 來做為 CI 的平台,前陣子在 Jenkins 上建立 Windows Store App 的建置工作時噴出三個錯誤訊息,很神奇的是,若使用 Cmd 操作 MSBuild.exe 編譯同一份 sln、proj 檔是正常的,一定要透過 Jenkins 啟動 MSBuild 才會碰到這個問題。

在 Jenkins 從 Version Control Server 把程式碼 Clone 下來後,使用 MSBuild 編譯不到幾秒就停止且出現以下錯誤訊息:

  C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\AppxPackage\Microsoft.AppXPackage.Targets(2241,9): error APPX0105: Cannot import the key file 'code_signing.pfx'. The key file may be password protected. To correct this, try to import the certificate manually into the current user’s personal certificate store. [D:\Jenkins\jobs\HubApp\workspace\HubApp\HubApp.Windows\HubApp.Windows.csproj]
  C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\AppxPackage\Microsoft.AppXPackage.Targets(2241,9): error APPX0102: A certificate with thumbprint '1E422D2EB0E02ABD8B5F0C4B77EEB30111C9D365' that is specified in the project cannot be found in the certificate store. Please specify a valid thumbprint in the project file. [D:\Jenkins\jobs\HubApp\workspace\HubApp\HubApp.Windows\HubApp.Windows.csproj]
  C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\AppxPackage\Microsoft.AppXPackage.Targets(2241,9): 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:\Jenkins\jobs\HubApp\HubApp\HubApp.Windows\HubApp.Windows.csproj]

在搜尋後發現很多不同的解決,但我試了沒效,最後找到某篇文章的解法照著做終於解決了這三個錯誤,會出現這三個錯誤的原因在於專案本身沒有指定 Sign Key,憑證的規格有很多種,在 Windows Store App 上是使用 pfx 或 p12 這種,產生的方法可以參考官方文件:How to create an app package signing certificate

通常在建立 Store App 時專案內就會有一個 XXX_TemporaryKey.pfx 的檔案可以直接使用,這個憑證的資訊會被記錄於 Package.appxmanifest 中,但不會被記錄在 Project 內,這三個錯誤訊息就是因為這個原因而產生的。

要解決這個問題,只需要在 "專案上點右鍵"、選擇 "Properties" 再切到 "Signing" 這個 Tab 並且將 "Sign the assembly" 打勾後,選擇和 Package.appxmanifest 內 Packaging、Publisher 同樣的 pfx 即可,畫面如下




沒有留言:

張貼留言