unpackaged: allow building an unpackaged distribution from layout (#15133)

This PR adds a convenience feature to New-UnpackagedTerminalDistribution
that produces an unpackaged layout from an already-unpacked AppX, like
the one Visual Studio registers.

```powershell
New-UnpackagedTerminalDistribution `
    -TerminalLayout path\to\bin\x64\Debug\AppX `
    -XamlAppX path\to\xaml\2.8.appx
```

The output item when you build an unpackaged layout is the temp folder
in which the distribution was built. It will not make a zip file for
you.
This commit is contained in:
Dustin L. Howett 2023-04-20 07:47:05 -05:00 committed by GitHub
parent 2c165438ef
commit 2fd33ba510
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,21 +1,28 @@
[CmdletBinding(DefaultParameterSetName = 'AppX')]
Param( Param(
[Parameter(Mandatory, [Parameter(Mandatory, HelpMessage="Path to Terminal AppX", ParameterSetName = 'AppX')]
HelpMessage="Path to Terminal AppX")]
[ValidateScript({Test-Path $_ -Type Leaf})] [ValidateScript({Test-Path $_ -Type Leaf})]
[string] [string]
$TerminalAppX, $TerminalAppX,
[Parameter(Mandatory, [Parameter(Mandatory, HelpMessage="Path to Terminal Layout Deployment", ParameterSetName='Layout')]
HelpMessage="Path to Xaml AppX")] [ValidateScript({Test-Path $_ -Type Container})]
[string]
$TerminalLayout,
[Parameter(Mandatory, HelpMessage="Path to Xaml AppX", ParameterSetName='AppX')]
[Parameter(Mandatory, HelpMessage="Path to Xaml AppX", ParameterSetName='Layout')]
[ValidateScript({Test-Path $_ -Type Leaf})] [ValidateScript({Test-Path $_ -Type Leaf})]
[string] [string]
$XamlAppX, $XamlAppX,
[Parameter(HelpMessage="Output Directory")] [Parameter(HelpMessage="Output Directory", ParameterSetName='AppX')]
[Parameter(HelpMessage="Output Directory", ParameterSetName='Layout')]
[string] [string]
$Destination = ".", $Destination = ".",
[Parameter(HelpMessage="Path to makeappx.exe")] [Parameter(HelpMessage="Path to makeappx.exe", ParameterSetName='AppX')]
[Parameter(HelpMessage="Path to makeappx.exe", ParameterSetName='Layout')]
[ValidateScript({Test-Path $_ -Type Leaf})] [ValidateScript({Test-Path $_ -Type Leaf})]
[string] [string]
$MakeAppxPath = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\MakeAppx.exe" $MakeAppxPath = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\MakeAppx.exe"
@ -36,14 +43,17 @@ $tempDir = Join-Path ([System.IO.Path]::GetTempPath()) "tmp$([Convert]::ToString
New-Item -ItemType Directory -Path $tempDir | Out-Null New-Item -ItemType Directory -Path $tempDir | Out-Null
$XamlAppX = Get-Item $XamlAppX | Select-Object -Expand FullName $XamlAppX = Get-Item $XamlAppX | Select-Object -Expand FullName
$TerminalAppX = Get-Item $TerminalAppX | Select-Object -Expand FullName
######## ########
# Reading the AppX Manifest for preliminary info # Reading the AppX Manifest for preliminary info
######## ########
If ($TerminalAppX) {
$appxManifestPath = Join-Path $tempDir AppxManifest.xml $appxManifestPath = Join-Path $tempDir AppxManifest.xml
& tar.exe -x -f "$TerminalAppX" -C $tempDir AppxManifest.xml & tar.exe -x -f "$TerminalAppX" -C $tempDir AppxManifest.xml
} ElseIf($TerminalLayout) {
$appxManifestPath = Join-Path $TerminalLayout AppxManifest.xml
}
$manifest = [xml](Get-Content $appxManifestPath) $manifest = [xml](Get-Content $appxManifestPath)
$pfn = $manifest.Package.Identity.Name $pfn = $manifest.Package.Identity.Name
$version = $manifest.Package.Identity.Version $version = $manifest.Package.Identity.Version
@ -57,13 +67,20 @@ $terminalDir = "terminal-{0}" -f ($version)
######## ########
$terminalAppPath = Join-Path $tempdir $terminalDir $terminalAppPath = Join-Path $tempdir $terminalDir
$xamlAppPath = Join-Path $tempdir "xaml"
If ($TerminalAppX) {
$TerminalAppX = Get-Item $TerminalAppX | Select-Object -Expand FullName
New-Item -ItemType Directory -Path $terminalAppPath | Out-Null New-Item -ItemType Directory -Path $terminalAppPath | Out-Null
New-Item -ItemType Directory -Path $xamlAppPath | Out-Null
& $MakeAppxPath unpack /p $TerminalAppX /d $terminalAppPath /o | Out-Null & $MakeAppxPath unpack /p $TerminalAppX /d $terminalAppPath /o | Out-Null
If ($LASTEXITCODE -Ne 0) { If ($LASTEXITCODE -Ne 0) {
Throw "Unpacking $TerminalAppX failed" Throw "Unpacking $TerminalAppX failed"
} }
} ElseIf ($TerminalLayout) {
Copy-Item -Recurse -Path $TerminalLayout -Destination $terminalAppPath
}
$xamlAppPath = Join-Path $tempdir "xaml"
New-Item -ItemType Directory -Path $xamlAppPath | Out-Null
& $MakeAppxPath unpack /p $XamlAppX /d $xamlAppPath /o | Out-Null & $MakeAppxPath unpack /p $XamlAppX /d $xamlAppPath /o | Out-Null
If ($LASTEXITCODE -Ne 0) { If ($LASTEXITCODE -Ne 0) {
Throw "Unpacking $XamlAppX failed" Throw "Unpacking $XamlAppX failed"
@ -105,13 +122,19 @@ $finalTerminalPriFile = Join-Path $terminalAppPath "resources.pri"
-TerminalRoot $terminalAppPath ` -TerminalRoot $terminalAppPath `
-XamlRoot $xamlAppPath ` -XamlRoot $xamlAppPath `
-OutputPath $finalTerminalPriFile ` -OutputPath $finalTerminalPriFile `
-Verbose:$Verbose -Verbose:$Verbose | Out-Host
######## ########
# Packaging # Packaging
######## ########
If ($PSCmdlet.ParameterSetName -Eq "AppX") {
# We only produce a ZIP when we're combining two AppX directories.
New-Item -ItemType Directory -Path $Destination -ErrorAction:SilentlyContinue | Out-Null New-Item -ItemType Directory -Path $Destination -ErrorAction:SilentlyContinue | Out-Null
$outputZip = (Join-Path $Destination ("{0}.zip" -f ($distributionName))) $outputZip = (Join-Path $Destination ("{0}.zip" -f ($distributionName)))
& tar -c --format=zip -f $outputZip -C $tempDir $terminalDir & tar -c --format=zip -f $outputZip -C $tempDir $terminalDir
Remove-Item -Recurse -Force $tempDir -EA:SilentlyContinue
Get-Item $outputZip Get-Item $outputZip
} ElseIf ($PSCmdlet.ParameterSetName -Eq "Layout") {
Get-Item $terminalAppPath
}