Skip to content

Commit 73114ee

Browse files
SteveL-MSFTTravisEz13
authored andcommitted
Enable building of msix package (PowerShell#9289)
Add support in packaging.psm1 to produce a .msix AppX package. Update the docker image to use the new msix package type. Update the associated yml files so AzDevOps performs the build. ## PR Context Enable publishing PSCore6 to Microsoft Store
1 parent 23451ac commit 73114ee

13 files changed

Lines changed: 208 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dotnet-uninstall-debian-packages.sh
3434
*.exe
3535
*.msi
3636
*.appx
37+
*.msix
3738

3839
# Ignore binaries and symbols
3940
*.pdb

assets/AppxManifest.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<Package IgnorableNamespaces="uap mp rescap desktop6"
4+
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
5+
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
6+
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
7+
xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
8+
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
9+
xmlns:desktop6="http://schemas.microsoft.com/appx/manifest/desktop/windows10/6"
10+
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities">
11+
12+
<Identity Name="Microsoft.PowerShell" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" Version="$VERSION$" />
13+
14+
<Properties>
15+
<DisplayName>PowerShell Core 6</DisplayName>
16+
<PublisherDisplayName>Microsoft Corporation</PublisherDisplayName>
17+
<Logo>assets\StoreLogo.png</Logo>
18+
<desktop6:RegistryWriteVirtualization>disabled</desktop6:RegistryWriteVirtualization>
19+
<desktop6:FileSystemWriteVirtualization>disabled</desktop6:FileSystemWriteVirtualization>
20+
</Properties>
21+
22+
<Dependencies>
23+
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.17763.0" />
24+
</Dependencies>
25+
26+
<Resources>
27+
<Resource Language="en-US"/>
28+
</Resources>
29+
30+
<Applications>
31+
<Application Id="App" Executable="pwsh.exe" EntryPoint="Windows.FullTrustApplication">
32+
<Extensions>
33+
<uap3:Extension Category="windows.appExecutionAlias" EntryPoint="Windows.FullTrustApplication" Executable="pwsh.exe">
34+
<uap3:AppExecutionAlias>
35+
<desktop:ExecutionAlias Alias="pwsh.exe" />
36+
</uap3:AppExecutionAlias>
37+
</uap3:Extension>
38+
</Extensions>
39+
<uap:VisualElements DisplayName="PowerShell Core 6" Description="PowerShell is an automation and configuration management platform. It consists of a cross-platform (Windows, Linux, and macOS) command-line shell and associated scripting language." BackgroundColor="transparent" Square150x150Logo="assets\Square150x150Logo.png" Square44x44Logo="assets\Square44x44Logo.png">
40+
</uap:VisualElements>
41+
</Application>
42+
</Applications>
43+
44+
<Capabilities>
45+
<Capability Name="internetClient" />
46+
<rescap:Capability Name="runFullTrust" />
47+
<rescap:Capability Name="unvirtualizedResources" />
48+
</Capabilities>
49+
</Package>

assets/Square150x150Logo.png

10.6 KB
Loading

assets/Square44x44Logo.png

1.97 KB
Loading
1.97 KB
Loading
1.97 KB
Loading

assets/StoreLogo.png

3 KB
Loading

tools/packaging/packaging.psm1

Lines changed: 115 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Start-PSPackage {
2525
[string]$Name = "powershell",
2626

2727
# Ubuntu, CentOS, Fedora, macOS, and Windows packages are supported
28-
[ValidateSet("deb", "osxpkg", "rpm", "msi", "zip", "nupkg", "tar", "tar-arm", "tar-arm64", "tar-alpine", "fxdependent")]
28+
[ValidateSet("msix", "deb", "osxpkg", "rpm", "msi", "zip", "nupkg", "tar", "tar-arm", "tar-arm64", "tar-alpine", "fxdependent")]
2929
[string[]]$Type,
3030

3131
# Generate windows downlevel package
@@ -254,7 +254,7 @@ function Start-PSPackage {
254254
} elseif ($Environment.IsMacOS) {
255255
"osxpkg", "nupkg", "tar"
256256
} elseif ($Environment.IsWindows) {
257-
"msi", "nupkg"
257+
"msi", "nupkg", "msix"
258258
}
259259
Write-Warning "-Type was not specified, continuing with $Type!"
260260
}
@@ -335,6 +335,18 @@ function Start-PSPackage {
335335
New-MSIPackage @Arguments
336336
}
337337
}
338+
"msix" {
339+
$Arguments = @{
340+
ProductNameSuffix = $NameSuffix
341+
ProductSourcePath = $Source
342+
ProductVersion = $Version
343+
Force = $Force
344+
}
345+
346+
if ($PSCmdlet.ShouldProcess("Create MSIX Package")) {
347+
New-MSIXPackage @Arguments
348+
}
349+
}
338350
'nupkg' {
339351
$Arguments = @{
340352
PackageNameSuffix = $NameSuffix
@@ -2726,6 +2738,107 @@ function New-MSIPackage
27262738
}
27272739
}
27282740

2741+
<#
2742+
.Synopsis
2743+
Creates a Windows AppX MSIX package and assumes that the binaries are already built using 'Start-PSBuild'.
2744+
This only works on a Windows machine due to the usage of makeappx.exe.
2745+
.EXAMPLE
2746+
# This example shows how to produce a Debug-x64 installer for development purposes.
2747+
cd $RootPathOfPowerShellRepo
2748+
Import-Module .\build.psm1; Import-Module .\tools\packaging\packaging.psm1
2749+
New-MSIXPackage -Verbose -ProductSourcePath '.\src\powershell-win-core\bin\Debug\netcoreapp2.1\win7-x64\publish' -ProductTargetArchitecture x64 -ProductVersion '1.2.3'
2750+
#>
2751+
function New-MSIXPackage
2752+
{
2753+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='Low')]
2754+
param (
2755+
2756+
# Name of the Product
2757+
[ValidateNotNullOrEmpty()]
2758+
[string] $ProductName = 'PowerShell',
2759+
2760+
# Suffix of the Name
2761+
[string] $ProductNameSuffix,
2762+
2763+
# Version of the Product
2764+
[Parameter(Mandatory = $true)]
2765+
[ValidateNotNullOrEmpty()]
2766+
[string] $ProductVersion,
2767+
2768+
# Source Path to the Product Files - required to package the contents into an MSIX
2769+
[Parameter(Mandatory = $true)]
2770+
[ValidateNotNullOrEmpty()]
2771+
[string] $ProductSourcePath,
2772+
2773+
# Force overwrite of package
2774+
[Switch] $Force
2775+
)
2776+
2777+
$makeappx = Get-Command makeappx -CommandType Application -ErrorAction Ignore
2778+
if ($null -eq $makeappx) {
2779+
# This is location in our dockerfile
2780+
$dockerPath = Join-Path $env:SystemDrive "makeappx"
2781+
if (Test-Path $dockerPath) {
2782+
$makeappx = Get-ChildItem $dockerPath -Include makeappx.exe -Recurse | Select-Object -First 1
2783+
}
2784+
2785+
if ($null -eq $makeappx) {
2786+
# Try to find in well known location
2787+
$makeappx = Get-ChildItem "${env:ProgramFiles(x86)}\Windows Kits\10\bin\*\x64" -Include makeappx.exe -Recurse | Select-Object -First 1
2788+
if ($null -eq $makeappx) {
2789+
throw "Could not locate makeappx.exe, make sure Windows 10 SDK is installed"
2790+
}
2791+
}
2792+
}
2793+
2794+
$makepri = Get-Item (Join-Path $makeappx.Directory "makepri.exe") -ErrorAction Stop
2795+
2796+
$ProductSemanticVersion = Get-PackageSemanticVersion -Version $ProductVersion
2797+
$productSemanticVersionWithName = $ProductName + '-' + $ProductSemanticVersion
2798+
$packageName = $productSemanticVersionWithName
2799+
if ($ProductNameSuffix) {
2800+
$packageName += "-$ProductNameSuffix"
2801+
}
2802+
2803+
$ProductVersion = Get-PackageVersionAsMajorMinorBuildRevision -Version $ProductVersion
2804+
if (([Version]$ProductVersion).Revision -eq -1) {
2805+
$ProductVersion += ".0"
2806+
}
2807+
2808+
# Appx manifest needs to be in root of source path, but the embedded version needs to be updated
2809+
$appxManifest = Get-Content "$RepoRoot\assets\AppxManifest.xml" -Raw
2810+
$appxManifest = $appxManifest.Replace('$VERSION$', $ProductVersion)
2811+
Set-Content -Path "$ProductSourcePath\AppxManifest.xml" -Value $appxManifest -Force
2812+
# Necessary image assets need to be in source assets folder
2813+
$assets = @(
2814+
'Square150x150Logo.png'
2815+
'Square44x44Logo.png'
2816+
'Square44x44Logo.targetsize-48.png'
2817+
'Square44x44Logo.targetsize-48_altform-unplated.png'
2818+
'StoreLogo.png'
2819+
)
2820+
2821+
if (!(Test-Path "$ProductSourcePath\assets")) {
2822+
$null = New-Item -ItemType Directory -Path "$ProductSourcePath\assets"
2823+
}
2824+
2825+
$assets | ForEach-Object {
2826+
Copy-Item -Path "$RepoRoot\assets\$_" -Destination "$ProductSourcePath\assets\"
2827+
}
2828+
2829+
if ($PSCmdlet.ShouldProcess("Create .msix package?")) {
2830+
Write-Verbose "Creating priconfig.xml" -Verbose
2831+
Start-NativeExecution -VerboseOutputOnError { & $makepri createconfig /o /cf (Join-Path $ProductSourcePath "priconfig.xml") /dq en-US }
2832+
Write-Verbose "Creating resources.pri" -Verbose
2833+
Push-Location $ProductSourcePath
2834+
Start-NativeExecution -VerboseOutputOnError { & $makepri new /v /o /pr $ProductSourcePath /cf (Join-Path $ProductSourcePath "priconfig.xml") }
2835+
Pop-Location
2836+
Write-Verbose "Creating msix package" -Verbose
2837+
Start-NativeExecution -VerboseOutputOnError { & $makeappx pack /o /v /h SHA256 /d $ProductSourcePath /p (Join-Path -Path $PWD -ChildPath "$packageName.msix") }
2838+
Write-Verbose "Created $packageName.msix" -Verbose
2839+
}
2840+
}
2841+
27292842
# verify no files have been added or removed
27302843
# if so, write an error with details
27312844
function Test-FileWxs

tools/releaseBuild/Images/microsoft_powershell_windowsservercore/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ COPY wix.psm1 containerFiles/wix.psm1
1919
RUN Import-Module ./containerFiles/wix.psm1; `
2020
Install-WixZip -zipPath \wix.Zip
2121

22+
# Install makeappx and makepri
23+
ADD https://pscoretestdata.blob.core.windows.net/build-files/makeappx/makeappx.zip?sp=r&st=2019-04-05T18:02:52Z&se=2020-04-06T02:02:52Z&spr=https&sv=2018-03-28&sig=t07uC1K3uFLtINQsmorHobgPh%2B%2BBgjFnmHEJGNZT6Hk%3D&sr=b /makeappx.zip
24+
RUN Expand-Archive /makeappx.zip
25+
2226
COPY PowerShellPackage.ps1 /
2327

2428
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1

tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,19 @@ try{
116116
$pspackageParams = @{'Type'='msi'; 'WindowsRuntime'=$Runtime}
117117
}
118118

119-
if (!$ComponentRegistration.IsPresent -and !$Symbols.IsPresent -and $Runtime -notmatch "arm" -and $Runtime -ne 'fxdependent')
119+
if (!$ComponentRegistration.IsPresent -and !$Symbols.IsPresent -and $Runtime -notmatch 'arm' -and $Runtime -ne 'fxdependent')
120120
{
121121
Write-Verbose "Starting powershell packaging(msi)..." -verbose
122122
Start-PSPackage @pspackageParams @releaseTagParam
123123
}
124124

125+
if (!$ComponentRegistration.IsPresent -and !$Symbols.IsPresent -and $Runtime -notin 'win7-x86','fxdependent')
126+
{
127+
$pspackageParams['Type']='msix'
128+
Write-Verbose "Starting powershell packaging(msix)..." -verbose
129+
Start-PSPackage @pspackageParams @releaseTagParam
130+
}
131+
125132
if (!$ComponentRegistration.IsPresent -and $Runtime -ne 'fxdependent')
126133
{
127134
$pspackageParams['Type']='zip'
@@ -131,7 +138,7 @@ try{
131138

132139
Write-Verbose "Exporting packages ..." -verbose
133140

134-
Get-ChildItem $location\*.msi,$location\*.zip,$location\*.wixpdb | ForEach-Object {
141+
Get-ChildItem $location\*.msi,$location\*.zip,$location\*.wixpdb,$location\*.msix | ForEach-Object {
135142
$file = $_.FullName
136143
Write-Verbose "Copying $file to $destination" -verbose
137144
Copy-Item -Path $file -Destination "$destination\" -Force

0 commit comments

Comments
 (0)