Skip to content

Commit 2020751

Browse files
committed
build: wixv4 msi build (fixes #1)
This commit adds a WiX v4 MSI build to the project. The build is run from the msi/build.ps1 script. A GitHub workflow is added to run the build and upload the MSI as an artifact.
1 parent 761d61e commit 2020751

File tree

8 files changed

+201
-0
lines changed

8 files changed

+201
-0
lines changed

.github/workflows/msi.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build the MSI (Installer)
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build-msi:
13+
name: 🪟 Build the MSI
14+
runs-on: windows-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: ⚙️ Setup dotnet
20+
uses: actions/setup-dotnet@v4
21+
with:
22+
dotnet-version: 7.0.x
23+
24+
- name: 🔨 Build the MSI
25+
run: ./msi/build.ps1
26+
27+
- name: 📦 Upload the MSI
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: "WSL USB Manager.msi"
31+
path: "msi/bin/Release/WSL USB Manager.msi"

msi/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
obj
2+
.wix
3+
bin
4+
staging

msi/Package.wxs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<!-- Copyright (c) 2024 JP Hutchins -->
2+
<!-- SPDX-License-Identifier: MIT -->
3+
4+
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
5+
xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">
6+
7+
<Package Name="$(env.PRODUCT_NAME)"
8+
Manufacturer="$(env.COMPANY_NAME)"
9+
Version="$(env.VERSION)"
10+
UpgradeCode="b958955b-2aef-4047-9319-642cb9c57b17"
11+
ProductCode="*"
12+
Language="1033"
13+
Codepage="1252"
14+
InstallerVersion="450">
15+
16+
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed" />
17+
18+
<Media Id="1"
19+
Cabinet="media1.cab"
20+
EmbedCab="yes"
21+
DiskPrompt="CD-ROM #1" />
22+
<Property Id="DiskPrompt"
23+
Value="$(env.PRODUCT_NAME) Installation" />
24+
25+
<Icon Id="Icon"
26+
SourceFile="../resources/wsl-usb-manager.ico" />
27+
<Property Id="ARPPRODUCTICON"
28+
Value="Icon" />
29+
30+
<Feature Id="Main"
31+
Title="$(env.PRODUCT_NAME)"
32+
Description="Installs all application files."
33+
Level="1"
34+
ConfigurableDirectory="APPLICATIONFOLDER"
35+
AllowAdvertise="no"
36+
Display="expand"
37+
AllowAbsent="no">
38+
39+
<ComponentGroupRef Id="HarvestedComponents"/>
40+
41+
<Feature Id="StartMenuFolderFeature"
42+
Title="Start Menu Folder"
43+
Description="Add $(env.PRODUCT_NAME) to the Start Menu."
44+
Level="1">
45+
<ComponentRef Id="ProgramMenuShortcuts" />
46+
</Feature>
47+
</Feature>
48+
49+
<UI>
50+
<ui:WixUI Id="WixUI_FeatureTree" />
51+
<Publish Dialog="WelcomeDlg"
52+
Control="Next"
53+
Event="NewDialog"
54+
Value="CustomizeDlg"
55+
Order="99" />
56+
<Publish Dialog="CustomizeDlg"
57+
Control="Back"
58+
Event="NewDialog"
59+
Value="WelcomeDlg"
60+
Order="99" />
61+
</UI>
62+
63+
<StandardDirectory Id="ProgramFiles6432Folder">
64+
<Directory Id="APPLICATIONFOLDER"
65+
Name="$(env.PRODUCT_NAME)">
66+
</Directory>
67+
</StandardDirectory>
68+
69+
<WixVariable Id="WixUIBannerBmp"
70+
Value="WixUIBannerBmp.png" />
71+
72+
<WixVariable Id="WixUIDialogBmp"
73+
Value="WixUIDialogBmp.png" />
74+
75+
76+
<StandardDirectory Id="ProgramMenuFolder">
77+
<Directory Id="ProgramMenuDirFolder"
78+
Name="$(env.PRODUCT_NAME)">
79+
<Component Id="ProgramMenuShortcuts"
80+
Guid="97faee7a-2d17-4394-9869-2c9669ef2afe">
81+
<Shortcut Id="UninstallProduct"
82+
Name="Uninstall $(env.PRODUCT_NAME)"
83+
Description="Uninstalls $(env.PRODUCT_NAME)"
84+
Target="[System64Folder]msiexec.exe"
85+
Arguments="/x [ProductCode]"
86+
Directory="ProgramMenuDirFolder"
87+
Show="normal" />
88+
<Shortcut Id="Shortcut"
89+
Name="WSL USB Manager"
90+
Description="Start WSL USB Manager"
91+
Target="[APPLICATIONFOLDER]$(env.EXE_NAME)"
92+
Directory="ProgramMenuDirFolder"
93+
Show="normal" />
94+
<RemoveFolder Id="ProgramMenuDirFolder"
95+
On="uninstall" />
96+
<RegistryValue Root="HKCU"
97+
Key="Software\[Manufacturer]\[ProductName]"
98+
Name="installed"
99+
Type="integer"
100+
Value="1"
101+
KeyPath="yes" />
102+
</Component>
103+
</Directory>
104+
</StandardDirectory>
105+
106+
</Package>
107+
108+
</Wix>

msi/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Create an MSI (Installer)
2+
3+
From the root of the repository, run the build script:
4+
5+
```powershell
6+
./msi/build.ps1
7+
```

msi/WixUIBannerBmp.png

3.2 KB
Loading

msi/WixUIDialogBmp.png

15.7 KB
Loading

msi/build.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) 2024 JP Hutchins
2+
# SPDX-License-Identifier: MIT
3+
4+
# Build the release
5+
cargo build --release
6+
7+
# Clean the msi directory
8+
dotnet clean msi
9+
10+
# mkdir the staging directory if it doesn't exist
11+
New-Item -ItemType Directory -Path msi/staging -Force
12+
13+
# Copy the files to the staging directory
14+
Copy-Item target/release/wsl-usb-manager.exe msi/staging/wsl-usb-manager.exe
15+
Copy-Item LICENSE.md msi/staging/LICENSE.md
16+
17+
# Run a dotnet build with some environment variables set
18+
$env:COMPANY_NAME = "WSL USB Manager"
19+
$env:PRODUCT_NAME = "WSL USB Manager"
20+
$env:APP_NAME = "wsl-usb-manager"
21+
$env:EXE_NAME = "wsl-usb-manager.exe"
22+
$env:VERSION = (Get-Content Cargo.toml | Select-String -Pattern '^version\s*=\s*"(.*)"' | ForEach-Object { $_.Matches[0].Groups[1].Value })
23+
$env:PORTABLE_PATH = "staging"
24+
$env:MSI_NAME = "WSL USB Manager"
25+
26+
dotnet build msi --configuration Release

msi/wsl-usb-manager.wixproj

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!-- Copyright (c) 2024 JP Hutchins -->
2+
<!-- SPDX-License-Identifier: MIT -->
3+
4+
<Project Sdk="WixToolset.Sdk/4.0.4">
5+
<PropertyGroup>
6+
<DefineConstants> ApplicationFiles=$(PORTABLE_PATH)/
7+
</DefineConstants>
8+
<OutputName>$(MSI_NAME)</OutputName>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="WixToolset.Heat" Version="4.0.4" />
13+
<PackageReference Include="WixToolset.UI.wixext" Version="4.0.4" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<HarvestDirectory Include="$(PORTABLE_PATH)/">
18+
<ComponentGroupName>HarvestedComponents</ComponentGroupName>
19+
<DirectoryRefId>APPLICATIONFOLDER</DirectoryRefId>
20+
<SuppressRootDirectory>true</SuppressRootDirectory>
21+
<SuppressRegistry>true</SuppressRegistry>
22+
<PreprocessorVariable>var.ApplicationFiles</PreprocessorVariable>
23+
</HarvestDirectory>
24+
</ItemGroup>
25+
</Project>

0 commit comments

Comments
 (0)