# Deploy Scripts

> MSIX loose-file registration, Deploy.ps1, WinAppDeployCmd, and ADB deployment

- Skill: `gabrielmoreira/deploy-scripts` (Agent Skill)
- Install (CLI): `npx skillmds@latest add gabrielmoreira/deploy-scripts`
- Raw SKILL.md: https://api.skillmd.com/api/skills/gabrielmoreira/deploy-scripts/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: gabrielmoreira (https://skillmd.com/u/gabrielmoreira)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/gabrielmoreira/deploy-scripts

---


When working on projects related to deployment script patterns, apply this domain knowledge.

# Deployment Scripts — Domain Knowledge

## Deploy.ps1 Pattern for MSIX Loose-File Registration

### MSBuild Auto-Detection
```powershell
# Find MSBuild via vswhere
$vswhere = "${env:ProgramFiles(x86)}\\Microsoft Visual Studio\\Installer\\vswhere.exe"
$vsInstall = & $vswhere -latest -requires Microsoft.Component.MSBuild -property installationPath
$msbuild = Join-Path $vsInstall "MSBuild\\Current\\Bin\\amd64\\MSBuild.exe"
```

### Architecture Detection
```powershell
$arch = if ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq 'Arm64') {
    'ARM64'
} else {
    'x64'
}
```

### Build for Loose-File Deployment
```powershell
& $msbuild MyApp.csproj /p:Configuration=$Configuration /p:Platform=$arch /p:WindowsPackageType=None
```
- `WindowsPackageType=None` produces unpackaged output suitable for loose-file registration.

### AppX Layout Assembly
1. Copy the compiled exe, dlls, and assets to a layout directory.
2. Generate AppxManifest.xml with token substitution:
   - Replace `$targetnametoken$` with actual assembly name.
   - Replace `$version$` with the assembly version.
   - Set correct `ProcessorArchitecture` (x64/arm64, not neutral).
3. Copy XBF (compiled XAML) resources.
4. Copy resources.pri (auto-generated by EnableMsixTooling).
5. Copy app assets (icons, splash screens).

### Local Registration
```powershell
Add-AppxPackage -Register "$layoutDir\\AppxManifest.xml"
```
- This registers the app for the current user from the loose files.
- App appears in Start menu immediately.
- Use `-ForceUpdateFromAnyVersion` if re-registering.

### Unregistration
```powershell
Get-AppxPackage -Name "MyApp.PackageName" | Remove-AppxPackage
```

### Remote Deployment (WinAppDeployCmd)
```powershell
# Deploy files to remote device
WinAppDeployCmd deployfiles -ip $DeviceIp -pin $Pin -file $layoutDir

# Register on remote device
WinAppDeployCmd registerfiles -ip $DeviceIp -pin $Pin -remotedeploydir $remotePath
```
- Use `deployfiles` first (copies TO device), then `registerfiles` (registers on device).
- PIN pairing required for first connection.

### Device Discovery
```powershell
WinAppDeployCmd devices -timeout 5
```
- Lists all discoverable devices on the local network.

## Android Deployment (ADB)

### Build and Deploy
```powershell
$env:JAVA_HOME = "C:\\Program Files\\Eclipse Adoptium\\jdk-22.0.2.9-hotspot"
.\\gradlew.bat assembleDebug --no-daemon
adb install -r app\\build\\outputs\\apk\\debug\\app-debug.apk
```

### Notes
- Android SDK read-only warnings ("Exception while marshalling ... package.xml") are harmless.
- `QUERY_ALL_PACKAGES` permission needed for Android 11+ (API 30) package visibility.
- Person.getName() requires API 28+ — use `@RequiresApi` or version check.
- WEBP_LOSSY compression requires API 30+; fallback to deprecated WEBP for older versions.

## CI/CD Deployment Considerations
- Use `concurrency: { group: ci-${{ github.ref }}, cancel-in-progress: true }`
  to cancel redundant CI runs on the same branch.
- MSIX builds in CI require MSBuild (not dotnet build) + setup-msbuild action.
- Test projects can use `dotnet test` even when the app requires MSBuild.

