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
# 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
$arch = if ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq 'Arm64') {
'ARM64'
} else {
'x64'
}
Build for Loose-File Deployment
& $msbuild MyApp.csproj /p:Configuration=$Configuration /p:Platform=$arch /p:WindowsPackageType=None
WindowsPackageType=Noneproduces unpackaged output suitable for loose-file registration.
AppX Layout Assembly
- Copy the compiled exe, dlls, and assets to a layout directory.
- 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).
- Replace
- Copy XBF (compiled XAML) resources.
- Copy resources.pri (auto-generated by EnableMsixTooling).
- Copy app assets (icons, splash screens).
Local Registration
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
-ForceUpdateFromAnyVersionif re-registering.
Unregistration
Get-AppxPackage -Name "MyApp.PackageName" | Remove-AppxPackage
Remote Deployment (WinAppDeployCmd)
# 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
deployfilesfirst (copies TO device), thenregisterfiles(registers on device). - PIN pairing required for first connection.
Device Discovery
WinAppDeployCmd devices -timeout 5
- Lists all discoverable devices on the local network.
Android Deployment (ADB)
Build and Deploy
$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_PACKAGESpermission needed for Android 11+ (API 30) package visibility.- Person.getName() requires API 28+ — use
@RequiresApior 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 testeven when the app requires MSBuild.