Skip to content

Commit c3fad58

Browse files
committed
SimpleWeather.Windows: add script to create .msixupload/.msixbundle
1 parent 171e608 commit c3fad58

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

Diff for: bundle-msix.ps1

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#MSIX Bundle script
2+
3+
param (
4+
[string]$BundleDir = "AppPackages",
5+
[string]$ProjectName = "SimpleWeather.Windows",
6+
[string]$Version
7+
)
8+
9+
if ([string]::IsNullOrWhiteSpace($BundleDir))
10+
{
11+
throw "Directory is invalid"
12+
}
13+
14+
if ([string]::IsNullOrWhiteSpace($ProjectName))
15+
{
16+
throw "ProjectName is invalid"
17+
}
18+
19+
$WorkingDir = pwd
20+
$PackageDir = [System.IO.Path]::Combine($WorkingDir, $ProjectName, $BundleDir)
21+
22+
$MsixBundleDir = ""
23+
24+
if ([string]::IsNullOrWhiteSpace($Version))
25+
{
26+
$filter = [string]::Format("{0}*_Test", $ProjectName)
27+
$MsixBundleDir = Get-ChildItem "$PackageDir" -Filter $filter -Directory | Sort -Descending | Select-Object -First 1
28+
29+
# Check version string
30+
$Version = "$MsixBundleDir".Replace("${ProjectName}_", "").Replace("_Test", "")
31+
32+
if ($Version -notmatch "[0-9]{1,5}.[0-9]{1,5}.[0-9]{1,5}.[0-9]{1,5}")
33+
{
34+
throw "Version does not match format x.x.x.x"
35+
}
36+
37+
$MsixBundleDir = [System.IO.Path]::Combine($PackageDir, $MsixBundleDir)
38+
}
39+
else
40+
{
41+
$filter = [string]::Format("{0}_{1}_Test", $ProjectName, $Version)
42+
$MsixBundleDir = Get-ChildItem "$PackageDir" -Filter $filter -Directory | Select-Object -First 1
43+
$MsixBundleDir = [System.IO.Path]::Combine($PackageDir, $MsixBundleDir)
44+
}
45+
46+
if ([string]::IsNullOrWhiteSpace($MsixBundleDir))
47+
{
48+
throw "Unable to find bundle dir"
49+
}
50+
else
51+
{
52+
$msixcount = (Get-ChildItem $MsixBundleDir -Filter "*.msix" -File | Measure-Object).Count
53+
54+
if ($msixcount -le 0)
55+
{
56+
throw "No .msix packages found"
57+
}
58+
59+
$BundleName = "${ProjectName}_${Version}"
60+
$BundleFileName = "${BundleName}.msixbundle"
61+
62+
$temp_dir = "${BundleName}_temp"
63+
$temp_dir = [System.IO.Path]::Combine($PackageDir, $temp_dir)
64+
65+
$null = [System.IO.Directory]::CreateDirectory($temp_dir)
66+
67+
Get-ChildItem $MsixBundleDir -Filter "*.msix" -File | Copy-Item -Destination $temp_dir
68+
69+
# Log output
70+
Write-Host "Output Dir: ${PackageDir}"
71+
Write-Host "Version: ${Version}"
72+
Write-Host "Bundle File: ${BundleName}"
73+
74+
# Create msixbundle
75+
$OutputBundleFile = [System.IO.Path]::Combine($temp_dir, $BundleFileName)
76+
MakeAppx bundle /bv $Version /d $temp_dir /p $OutputBundleFile
77+
78+
# Remove .msix files
79+
Get-ChildItem $temp_dir -Filter "*.msix" -File | Remove-Item
80+
81+
# Copy symbol files
82+
Get-ChildItem $MsixBundleDir -Filter "*.msixsym" -File | Copy-Item -Destination $temp_dir
83+
# Rename .msixsym -> .appxsym
84+
Get-ChildItem $temp_dir -Filter "*.msixsym" -File | Rename-Item -NewName {$_.name -replace ".msixsym",".appxsym"}
85+
86+
# Zip files
87+
$ZipFile = [System.IO.Path]::Combine($temp_dir, "${BundleName}.zip")
88+
Compress-Archive -Path ("$temp_dir\*.msixbundle", "$temp_dir\*.appxsym") -DestinationPath $ZipFile
89+
90+
# Move to final destination
91+
$OutputFile = [System.IO.Path]::Combine($PackageDir, "${BundleName}.msixupload")
92+
Move-Item $ZipFile -Destination $OutputFile
93+
94+
# Delete temp dir
95+
Remove-Item -Recurse -Force $temp_dir
96+
97+
Write-Host "Bundle file created: ${OutputFile}"
98+
}

0 commit comments

Comments
 (0)