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

added windows app sdk fetching and bundling into the installer #66

Merged
merged 3 commits into from
Apr 1, 2025
Merged
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
37 changes: 29 additions & 8 deletions Installer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public class BootstrapperOptions : SharedOptions
[Option('m', "msi-path", Required = true, HelpText = "Path to the MSI package to embed")]
public string MsiPath { get; set; }

[Option('w', "windows-app-sdk-path", Required = true, HelpText = "Path to the Windows App Sdk package to embed")]
public string WindowsAppSdkPath { get; set; }

public new void Validate()
{
base.Validate();
Expand All @@ -124,6 +127,8 @@ public class BootstrapperOptions : SharedOptions
throw new ArgumentException($"Logo PNG file not found at '{LogoPng}'", nameof(LogoPng));
if (!SystemFile.Exists(MsiPath))
throw new ArgumentException($"MSI package not found at '{MsiPath}'", nameof(MsiPath));
if (!SystemFile.Exists(WindowsAppSdkPath))
throw new ArgumentException($"Windows App Sdk package not found at '{WindowsAppSdkPath}'", nameof(WindowsAppSdkPath));
}
}

Expand Down Expand Up @@ -337,16 +342,11 @@ private static int BuildBundle(BootstrapperOptions opts)
{
opts.Validate();

if (!DotNetRuntimePackagePayloads.TryGetValue(opts.Platform, out var payload))
if (!DotNetRuntimePackagePayloads.TryGetValue(opts.Platform, out var dotNetRuntimePayload))
throw new ArgumentException($"Invalid architecture '{opts.Platform}' specified", nameof(opts.Platform));

// TODO: it would be nice to include the WindowsAppRuntime but
// Microsoft makes it difficult to check from a regular
// installer:
// https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/check-windows-app-sdk-versions
// https://github.com/microsoft/WindowsAppSDK/discussions/2437
var bundle = new Bundle(ProductName,
new ExePackage
new ExePackage // .NET Runtime
{
PerMachine = true,
// Don't uninstall the runtime when the bundle is uninstalled.
Expand All @@ -362,7 +362,28 @@ private static int BuildBundle(BootstrapperOptions opts)
// anyway. The MSI will fatally exit if the runtime really isn't
// available, and the user can install it themselves.
Vital = false,
Payloads = [payload],
Payloads = [dotNetRuntimePayload],
},
// TODO: right now we are including the Windows App Sdk in the bundle
// and always install it
// Microsoft makes it difficult to check if it exists from a regular installer:
// https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/check-windows-app-sdk-versions
// https://github.com/microsoft/WindowsAppSDK/discussions/2437
new ExePackage // Windows App Sdk
{
PerMachine = true,
Permanent = true,
Cache = PackageCacheAction.remove,
// There is no license agreement for this SDK.
InstallArguments = "--quiet",
Vital = false,
Payloads =
[
new ExePackagePayload
{
SourceFile = opts.WindowsAppSdkPath
}
],
},
new MsiPackage(opts.MsiPath)
{
Expand Down
34 changes: 34 additions & 0 deletions scripts/Get-WindowsAppSdk.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Usage: Get-WindowsAppSdk.ps1 -arch <x64|arm64>
param (
[ValidateSet("x64", "arm64")]
[Parameter(Mandatory = $true)]
[string] $arch
)

function Download-File([string] $url, [string] $outputPath, [string] $etagFile) {
Write-Host "Downloading '$url' to '$outputPath'"
# We use `curl.exe` here because `Invoke-WebRequest` is notoriously slow.
& curl.exe `
--progress-bar `
-v `
--show-error `
--fail `
--location `
--etag-compare $etagFile `
--etag-save $etagFile `
--output $outputPath `
$url
if ($LASTEXITCODE -ne 0) { throw "Failed to download $url" }
if (!(Test-Path $outputPath) -or (Get-Item $outputPath).Length -eq 0) {
throw "Failed to download '$url', output file '$outputPath' is missing or empty"
}
}

# Download the Windows App Sdk binary from Microsoft for this platform if we don't have
# it yet (or it's different).
$windowsAppSdkMajorVersion = "1.6"
$windowsAppSdkFullVersion = "1.6.250228001"
$windowsAppSdkPath = Join-Path $PSScriptRoot "files\windows-app-sdk-$($arch).exe"
$windowsAppSdkUri = "https://aka.ms/windowsappsdk/$($windowsAppSdkMajorVersion)/$($windowsAppSdkFullVersion)/windowsappruntimeinstall-$($arch).exe"
$windowsAppSdkEtagFile = $windowsAppSdkPath + ".etag"
Download-File $windowsAppSdkUri $windowsAppSdkPath $windowsAppSdkEtagFile
5 changes: 5 additions & 0 deletions scripts/Publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ Copy-Item $mutagenAgentsSrcPath $mutagenAgentsDestPath
if ($LASTEXITCODE -ne 0) { throw "Failed to build MSI" }
Add-CoderSignature $msiOutputPath

$getWindowsAppSdk = Join-Path $scriptRoot "Get-WindowsAppSdk.ps1"
& $getWindowsAppSdk -arch $arch
$windowsAppSdkPath = Join-Path $scriptRoot "files\windows-app-sdk-$($arch).exe"

# Build the bootstrapper
& dotnet.exe run --project .\Installer\Installer.csproj -c Release -- `
build-bootstrapper `
Expand All @@ -184,6 +188,7 @@ Add-CoderSignature $msiOutputPath
--output-path $outputPath `
--icon-file "App\coder.ico" `
--msi-path $msiOutputPath `
--windows-app-sdk-path $windowsAppSdkPath `
--logo-png "scripts\files\logo.png"
if ($LASTEXITCODE -ne 0) { throw "Failed to build bootstrapper" }

Expand Down
1 change: 1 addition & 0 deletions scripts/files/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mutagen-*.tar.gz
mutagen-*.exe
*.etag
windows-app-sdk-*.exe
Loading