Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build/add msi wixv4 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/msi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build the MSI (Installer)

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build-msi:
name: 🪟 Build the MSI
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: ⚙️ Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x

- name: 🔨 Build the MSI
run: ./msi/build.ps1

- name: 📦 Upload the MSI
uses: actions/upload-artifact@v4
with:
name: "WSL USB Manager.msi"
path: "msi/bin/Release/WSL USB Manager.msi"
4 changes: 4 additions & 0 deletions msi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
obj
.wix
bin
staging
108 changes: 108 additions & 0 deletions msi/Package.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!-- Copyright (c) 2024 JP Hutchins -->
<!-- SPDX-License-Identifier: MIT -->

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">

<Package Name="$(env.PRODUCT_NAME)"
Manufacturer="$(env.COMPANY_NAME)"
Version="$(env.VERSION)"
UpgradeCode="b958955b-2aef-4047-9319-642cb9c57b17"
ProductCode="*"
Language="1033"
Codepage="1252"
InstallerVersion="450">

<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed" />

<Media Id="1"
Cabinet="media1.cab"
EmbedCab="yes"
DiskPrompt="CD-ROM #1" />
<Property Id="DiskPrompt"
Value="$(env.PRODUCT_NAME) Installation" />

<Icon Id="Icon"
SourceFile="../resources/wsl-usb-manager.ico" />
<Property Id="ARPPRODUCTICON"
Value="Icon" />

<Feature Id="Main"
Title="$(env.PRODUCT_NAME)"
Description="Installs all application files."
Level="1"
ConfigurableDirectory="APPLICATIONFOLDER"
AllowAdvertise="no"
Display="expand"
AllowAbsent="no">

<ComponentGroupRef Id="HarvestedComponents"/>

<Feature Id="StartMenuFolderFeature"
Title="Start Menu Folder"
Description="Add $(env.PRODUCT_NAME) to the Start Menu."
Level="1">
<ComponentRef Id="ProgramMenuShortcuts" />
</Feature>
</Feature>

<UI>
<ui:WixUI Id="WixUI_FeatureTree" />
<Publish Dialog="WelcomeDlg"
Control="Next"
Event="NewDialog"
Value="CustomizeDlg"
Order="99" />
<Publish Dialog="CustomizeDlg"
Control="Back"
Event="NewDialog"
Value="WelcomeDlg"
Order="99" />
</UI>

<StandardDirectory Id="ProgramFiles6432Folder">
<Directory Id="APPLICATIONFOLDER"
Name="$(env.PRODUCT_NAME)">
</Directory>
</StandardDirectory>

<WixVariable Id="WixUIBannerBmp"
Value="WixUIBannerBmp.png" />

<WixVariable Id="WixUIDialogBmp"
Value="WixUIDialogBmp.png" />


<StandardDirectory Id="ProgramMenuFolder">
<Directory Id="ProgramMenuDirFolder"
Name="$(env.PRODUCT_NAME)">
<Component Id="ProgramMenuShortcuts"
Guid="97faee7a-2d17-4394-9869-2c9669ef2afe">
<Shortcut Id="UninstallProduct"
Name="Uninstall $(env.PRODUCT_NAME)"
Description="Uninstalls $(env.PRODUCT_NAME)"
Target="[System64Folder]msiexec.exe"
Arguments="/x [ProductCode]"
Directory="ProgramMenuDirFolder"
Show="normal" />
<Shortcut Id="Shortcut"
Name="WSL USB Manager"
Description="Start WSL USB Manager"
Target="[APPLICATIONFOLDER]$(env.EXE_NAME)"
Directory="ProgramMenuDirFolder"
Show="normal" />
<RemoveFolder Id="ProgramMenuDirFolder"
On="uninstall" />
<RegistryValue Root="HKCU"
Key="Software\[Manufacturer]\[ProductName]"
Name="installed"
Type="integer"
Value="1"
KeyPath="yes" />
</Component>
</Directory>
</StandardDirectory>

</Package>

</Wix>
7 changes: 7 additions & 0 deletions msi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Create an MSI (Installer)

From the root of the repository, run the build script:

```powershell
./msi/build.ps1
```
Binary file added msi/WixUIBannerBmp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added msi/WixUIDialogBmp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions msi/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2024 JP Hutchins
# SPDX-License-Identifier: MIT

# Build the release
cargo build --release

# Clean the msi directory
dotnet clean msi

# mkdir the staging directory if it doesn't exist
New-Item -ItemType Directory -Path msi/staging -Force

# Copy the files to the staging directory
Copy-Item target/release/wsl-usb-manager.exe msi/staging/wsl-usb-manager.exe
Copy-Item LICENSE.md msi/staging/LICENSE.md

# Run a dotnet build with some environment variables set
$env:COMPANY_NAME = "WSL USB Manager"
$env:PRODUCT_NAME = "WSL USB Manager"
$env:APP_NAME = "wsl-usb-manager"
$env:EXE_NAME = "wsl-usb-manager.exe"
$env:VERSION = (Get-Content Cargo.toml | Select-String -Pattern '^version\s*=\s*"(.*)"' | ForEach-Object { $_.Matches[0].Groups[1].Value })
$env:PORTABLE_PATH = "staging"
$env:MSI_NAME = "WSL USB Manager"

dotnet build msi --configuration Release
25 changes: 25 additions & 0 deletions msi/wsl-usb-manager.wixproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- Copyright (c) 2024 JP Hutchins -->
<!-- SPDX-License-Identifier: MIT -->

<Project Sdk="WixToolset.Sdk/4.0.4">
<PropertyGroup>
<DefineConstants> ApplicationFiles=$(PORTABLE_PATH)/
</DefineConstants>
<OutputName>$(MSI_NAME)</OutputName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="WixToolset.Heat" Version="4.0.4" />
<PackageReference Include="WixToolset.UI.wixext" Version="4.0.4" />
</ItemGroup>

<ItemGroup>
<HarvestDirectory Include="$(PORTABLE_PATH)/">
<ComponentGroupName>HarvestedComponents</ComponentGroupName>
<DirectoryRefId>APPLICATIONFOLDER</DirectoryRefId>
<SuppressRootDirectory>true</SuppressRootDirectory>
<SuppressRegistry>true</SuppressRegistry>
<PreprocessorVariable>var.ApplicationFiles</PreprocessorVariable>
</HarvestDirectory>
</ItemGroup>
</Project>