Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch Xamarin.iOS app from VS Code or terminal?

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

like image 626
Dominik Roszkowski Avatar asked Oct 18 '25 10:10

Dominik Roszkowski


1 Answers

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

  1. msbuild /t:Build

  2. Locate the mlaunch usually in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mlaunch. Just find your Xamarin.iOS.framework path

  3. 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

  1. Install your debug Xamarin.iOS app bundle and launch on the simulator
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.
like image 68
Tri Nguyen Avatar answered Oct 20 '25 16:10

Tri Nguyen