1 <# 2 .Synopsis 3 Compiles and signs an APPX package 4 .Description 5 Given the file listing, ensures all the contents are signed 6 and builds and signs the final package. 7 .Parameter mapfile 8 The location on disk of the text mapping file. 9 .Parameter msix 10 The path and name to store the APPX/MSIX. 11 .Parameter sign 12 When set, signs the APPX/MSIX. Packages to be published to 13 the store should not be signed. 14 .Parameter description 15 Description to embed in the signature (optional). 16 .Parameter certname 17 The name of the certificate to sign with (optional). 18 .Parameter certsha1 19 The SHA1 hash of the certificate to sign with (optional). 20 #> 21 param( 22 [Parameter(Mandatory=$true)][string]$layout, 23 [Parameter(Mandatory=$true)][string]$msix, 24 [switch]$sign, 25 [string]$description, 26 [string]$certname, 27 [string]$certsha1, 28 [string]$certfile 29 ) 30 31 $tools = $script:MyInvocation.MyCommand.Path | Split-Path -parent; 32 Import-Module $tools\sdktools.psm1 -WarningAction SilentlyContinue -Force 33 34 Set-Alias makeappx (Find-Tool "makeappx.exe") -Scope Script 35 Set-Alias makepri (Find-Tool "makepri.exe") -Scope Script 36 37 $msixdir = Split-Path $msix -Parent 38 if ($msixdir) { 39 $msixdir = (mkdir -Force $msixdir).FullName 40 } else { 41 $msixdir = Get-Location 42 } 43 $msix = Join-Path $msixdir (Split-Path $msix -Leaf) 44 45 pushd $layout 46 try { 47 if (Test-Path resources.pri) { 48 del resources.pri 49 } 50 $name = ([xml](gc AppxManifest.xml)).Package.Identity.Name 51 makepri new /pr . /mn AppxManifest.xml /in $name /cf _resources.xml /of _resources.pri /mf appx /o 52 if (-not $? -or -not (Test-Path _resources.map.txt)) { 53 throw "makepri step failed" 54 } 55 $lines = gc _resources.map.txt 56 $lines | ?{ -not ($_ -match '"_resources[\w\.]+?"') } | Out-File _resources.map.txt -Encoding utf8 57 makeappx pack /f _resources.map.txt /m AppxManifest.xml /o /p $msix 58 if (-not $?) { 59 throw "makeappx step failed" 60 } 61 } finally { 62 popd 63 } 64 65 if ($sign) { 66 Sign-File -certname $certname -certsha1 $certsha1 -certfile $certfile -description $description -files $msix 67 68 if (-not $?) { 69 throw "Package signing failed" 70 } 71 } 72