Skip to content

Instantly share code, notes, and snippets.

@brianmed
Created June 27, 2023 01:02
Show Gist options
  • Save brianmed/efc7453b4e218fc3ba2e1f053d61f73a to your computer and use it in GitHub Desktop.
Save brianmed/efc7453b4e218fc3ba2e1f053d61f73a to your computer and use it in GitHub Desktop.
.NET CLI Bash Script for Cleaning, Publishing, and Launching Maui apps. Currently iOS specific.
#! /bin/bash
set -e
GNU_GETOPT=getopt
# TODO: icky
if [ -d "/usr/local/Cellar/gnu-getopt/2.39/bin" ]; then
GNU_GETOPT="/usr/local/Cellar/gnu-getopt/2.39/bin/getopt"
fi
GOGO_DOTNET_ROOT="/usr/local/share/dotnet"
GOGO_IOS_APP_NAME=""
GOGO_IOS_DEVICE_NAME=""
GOGO_IOS_INSTALL=""
GOGO_IOS_RUN_AND_WAIT=""
GOGO_PROJECT_CLEAN=""
GOGO_PROJECT_PUBLISH=""
GOGO_PROJECT_CONFIGURATION="Debug"
GOGO_PROJECT_FRAMEWORK="net8.0-ios"
GOGO_PROJECT_RUNTIME="ios-arm64"
# Call getopt to validate the provided input.
options=$("$GNU_GETOPT" --alternative --options "" --longoptions dotnet-root: --longoptions ios-app-name: --longoptions ios-device-name: --longoptions ios-install --longoptions ios-run-and-wait --longoptions project-clean --longoptions project-configuration: --longoptions project-framework: --longoptions project-publish --longoptions project-runtime: -- "$@")
[ $? -eq 0 ] || {
echo "Incorrect options provided"
exit 1
}
eval set -- "$options"
while true; do
case "$1" in
--dotnet-root)
shift;
GOGO_DOTNET_ROOT=$1
;;
--ios-app-name)
shift;
GOGO_IOS_APP_NAME=$1
;;
--ios-device-name)
shift;
GOGO_IOS_DEVICE_NAME=$1
;;
--ios-install)
GOGO_IOS_INSTALL=1
;;
--ios-run-and-wait)
GOGO_IOS_RUN_AND_WAIT=1
;;
--project-clean)
GOGO_PROJECT_CLEAN=1
;;
--project-configuration)
shift;
GOGO_PROJECT_CONFIGURATION=$1
[[ ! $GOGO_PROJECT_CONFIGURATION =~ Debug|Release ]] && {
echo "Incorrect option ["$GOGO_PROJECT_CONFIGURATION"] provided: Debug|Release supported"
exit 1
}
;;
--project-framework)
shift;
GOGO_PROJECT_FRAMEWORK=$1
;;
--project-publish)
GOGO_PROJECT_PUBLISH=1
;;
--project-runtime)
shift;
GOGO_PROJECT_RUNTIME=$1
;;
--)
shift
break
;;
esac
shift
done
if [ -n "$GOGO_PROJECT_PUBLISH" ]; then
echo "Running: ""DOTNET_ROOT=$GOGO_DOTNET_ROOT" "$GOGO_DOTNET_ROOT"/dotnet publish -c "$GOGO_PROJECT_CONFIGURATION" -r $GOGO_PROJECT_RUNTIME -f "$GOGO_PROJECT_FRAMEWORK" -p:BuildType=Device
DOTNET_ROOT="$GOGO_DOTNET_ROOT" "$GOGO_DOTNET_ROOT"/dotnet publish -c "$GOGO_PROJECT_CONFIGURATION" -r $GOGO_PROJECT_RUNTIME -f "$GOGO_PROJECT_FRAMEWORK" -p:BuildType=Device
fi
if [ -n "$GOGO_PROJECT_CLEAN" ]; then
DOTNET_ROOT="$GOGO_DOTNET_ROOT" "$GOGO_DOTNET_ROOT"/dotnet clean -c "$GOGO_PROJECT_CONFIGURATION" -r $GOGO_PROJECT_RUNTIME -f "$GOGO_PROJECT_FRAMEWORK"
fi
if [ -n "$GOGO_IOS_INSTALL" -o -n "$GOGO_IOS_RUN_AND_WAIT" ]; then
IOS_SDK_VERSION=$(ls "$GOGO_DOTNET_ROOT"/packs/Microsoft.iOS.Sdk | sort -r | head -1)
fi
if [ -n "$GOGO_IOS_INSTALL" ]; then
if [ -z "$GOGO_IOS_APP_NAME" ]; then
echo "Need the iOS app name, eg 'CoffeMaker.app'"
exit 1
fi
if [ -z "$GOGO_IOS_DEVICE_NAME" ]; then
echo "Need the iOS device name, eg '00000000-0000000000000000'"
exit 1
fi
echo "Running: ""$GOGO_DOTNET_ROOT"/packs/Microsoft.iOS.Sdk/"$IOS_SDK_VERSION"/tools/bin/mlaunch --installdev "bin/$GOGO_PROJECT_CONFIGURATION/$GOGO_PROJECT_FRAMEWORK/$GOGO_PROJECT_RUNTIME/$GOGO_IOS_APP_NAME" --devname "$GOGO_IOS_DEVICE_NAME"
"$GOGO_DOTNET_ROOT"/packs/Microsoft.iOS.Sdk/"$IOS_SDK_VERSION"/tools/bin/mlaunch --installdev "bin/$GOGO_PROJECT_CONFIGURATION/$GOGO_PROJECT_FRAMEWORK/$GOGO_PROJECT_RUNTIME/$GOGO_IOS_APP_NAME" --devname "$GOGO_IOS_DEVICE_NAME"
fi
if [ -n "$GOGO_IOS_RUN_AND_WAIT" ]; then
echo "Running: ""$GOGO_DOTNET_ROOT"/packs/Microsoft.iOS.Sdk/"$IOS_SDK_VERSION"/tools/bin/mlaunch --launchdev "bin/$GOGO_PROJECT_CONFIGURATION/$GOGO_PROJECT_FRAMEWORK/$GOGO_PROJECT_RUNTIME/$GOGO_IOS_APP_NAME" --devname "$GOGO_IOS_DEVICE_NAME" --wait-for-exit
"$GOGO_DOTNET_ROOT"/packs/Microsoft.iOS.Sdk/"$IOS_SDK_VERSION"/tools/bin/mlaunch --launchdev "bin/$GOGO_PROJECT_CONFIGURATION/$GOGO_PROJECT_FRAMEWORK/$GOGO_PROJECT_RUNTIME/$GOGO_IOS_APP_NAME" --devname "$GOGO_IOS_DEVICE_NAME" --wait-for-exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment