Tri Nguyen's Blog
Mobile app development, Kotlin, Swift, Xamarin, KMM


Run Xamarin project from command line

Posted on

Update 2019, Oct 21: Add Build Archive for Xamarin.iOS

I feel pleasant working on Xamarin projects with VSCode in parallel with Jetbrains Rider IDE. It's neccessary to find a way to build and run Xamarin.iOS and Xamarin.Android apps using command line and generate those scripts as tasks in VSCode for quick development.

Run Xamarin.Android project from command line

msbuild /t:Build && msbuild /t:Install && adb shell monkey -p APP_PACKAGE_NAME 1

Notes

msbuild /t:Build
msbuild /t:Rebuild
msbuild /t:Clean
msbuild /t:Install
msbuild /t:Uninstall
msbuild /t:UpdateAndroidResources

Run Xamarin.iOS project from command line

Example build and run Xamarin.iOS app on iPhone XR, iOS 12.4 simulator

msbuild /t:Build && /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mlaunch --launchsim=bin/iPhoneSimulator/Debug/YOUR_IOS_PROJECT_NAME.app --device::v2:runtime=com.apple.CoreSimulator.SimRuntime.iOS-12-4,devicetype=com.apple.CoreSimulator.SimDeviceType.iPhone-XR

Notes

Explain steps to work with mlaunch

mlaunch --listsim simulators.xml

# simulators.xml is a temporary file that store all available simulators. Select a simulator (i.e iPhone XR), and keep the associated value of *SimRuntime* and *SimDeviceType* for later usage,
mlaunch --launchsim=IOS_APP_PATH --device::v2:runtime=SIM_RUNTIME,devicetype=SIM_DEVICE_TYPE

# *IOS_APP_PATH* is the path to *YOUR_IOS_PROJECT_NAME.app* file generated after *msbuild* step. The *--device* argument is constructed using the *SIM_RUNTIME* and *SIM_DEVICE_TYPE* value from the above step.

Others script for Xamarin.iOS

msbuild /t:Build /p:Configuration=Release /p:Platform=iPhone /p:ArchiveOnBuild=True