#!/usr/bin/env bash set -euo pipefail repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" dotnet_bin="${DOTNET_BIN:-${HOME}/.dotnet/dotnet}" developer_dir="${DEVELOPER_DIR:-/Applications/Xcode.app/Contents/Developer}" codesign_key="${UM_TRACE_DEVELOPMENT_KEY:-Apple Development: Brent Perteet (WZ56HVC6FD)}" codesign_profile="${UM_TRACE_DEVELOPMENT_PROVISION:-UM Trace Development}" device_udid="${1:-${UM_TRACE_DEVICE_UDID:-}}" if [[ -z "${device_udid}" && -f "${repo_dir}/.ios-device" ]]; then IFS= read -r device_udid < "${repo_dir}/.ios-device" fi if [[ -z "${device_udid}" ]]; then echo "Usage: $0 " >&2 echo "Alternatively, set UM_TRACE_DEVICE_UDID or save the UDID in ${repo_dir}/.ios-device." >&2 exit 2 fi if [[ ! -x "${dotnet_bin}" ]]; then echo "Missing .NET SDK at ${dotnet_bin}. Set DOTNET_BIN or install the local SDK." >&2 exit 2 fi if [[ ! -d "${developer_dir}" ]]; then echo "Missing Xcode developer directory at ${developer_dir}. Set DEVELOPER_DIR." >&2 exit 2 fi export DEVELOPER_DIR="${developer_dir}" "${dotnet_bin}" restore "${repo_dir}/FieldLogger/FieldLogger.csproj" \ -p:TargetFrameworks=net9.0-ios \ -p:RuntimeIdentifier=ios-arm64 # Restoring the MAUI head with a narrowed TargetFrameworks property can rewrite the # referenced headless library's assets file. Restore that library explicitly before building. "${dotnet_bin}" restore "${repo_dir}/src/FieldLogger.Sync/FieldLogger.Sync.csproj" # A partial MSBuild target (for example, a compile-only IDE validation) can leave a # FieldLogger.dll whose generated XAML code is newer than its embedded MauiXaml resources. # Always clear the narrowed iOS output before the real device build so App.xaml, page XAML, # app icons, and splash assets are regenerated as one consistent build graph. "${dotnet_bin}" clean "${repo_dir}/FieldLogger/FieldLogger.csproj" \ -f net9.0-ios \ -c Debug \ -p:TargetFrameworks=net9.0-ios \ -p:RuntimeIdentifier=ios-arm64 "${dotnet_bin}" build "${repo_dir}/FieldLogger/FieldLogger.csproj" \ -t:Run \ -p:TargetFrameworks=net9.0-ios \ -f net9.0-ios \ -c Debug \ -p:RuntimeIdentifier=ios-arm64 \ -p:_DeviceName="${device_udid}" \ -p:CodesignKey="${codesign_key}" \ -p:CodesignProvision="${codesign_profile}" \ --no-restore