I'd like to launch Xamarin.iOS app on an iPhone simulator on macOS via command line (or VS Code). Is there any way to do it in 2019?
I found that it's possible to build Xamarin app in this question. There's also this question but doesn't work on macOS. But is it possible to just launch (not necessarily debug) from command line? That would enable me to prepare config for VS Code.
I'm using Xamarin.iOS 12.14.0.114
Yes, it is possible using mlaunch tool in the way that Visual Studio does. It is still closed source but by reading its help page and xamarin-macios code. There is no need for IPA build but simply build for debug environment, use mlaunch for installing the app to the simulator/device and run it afterward.
Example: install and launch app after msbuild
/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mlaunch --launchsim=bin/iPhoneSimulator/Debug/IOS_PROJECT_NAME.app --device::v2:runtime=com.apple.CoreSimulator.SimRuntime.iOS-12-4,devicetype=com.apple.CoreSimulator.SimDeviceType.iPhone-XR
You should see Press enter to terminate the application message when the command is executed.
Explain
msbuild /t:Build
Locate the mlaunch
usually in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mlaunch
. Just find your Xamarin.iOS.framework path
List all available simulator with its runtime and device type value
mlaunch --listsim simulators.xml
Open the output file simulators.xml and select a simulator, i.e. iPhone XR, keep the value of SimRuntime
SimDeviceType
for the next step
mlaunch --launchsim=[IOS_APP_PATH] --device::v2:runtime=[SimRuntime],devicetype=[SimDeviceType]
--launchsim
is the relative path to your Xamarin.iOS app bundle built by msbuild task in the first step, usually bin/iPhoneSimulator/Debug/IOS_PROJECT_NAME.app
--device
composes of SimRuntime and SimDeviceType that you got from the XML file.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With