【问题标题】:How to launch Xamarin.iOS app from VS Code or terminal?如何从 VS Code 或终端启动 Xamarin.iOS 应用程序?
【发布时间】:2021-05-19 06:08:20
【问题描述】:

我想通过命令行(或 VS Code)在 macOS 上的 iPhone 模拟器上启动 Xamarin.iOS 应用程序。 2019年有什么办法吗?

我发现可以在this question 中构建 Xamarin 应用程序。还有this question,但不适用于 macOS。但是是否可以从命令行启动(不一定是调试)?这将使我能够为 VS Code 准备配置。

我正在使用 Xamarin.iOS 12.14.0.114

【问题讨论】:

    标签: xamarin xamarin.ios msbuild


    【解决方案1】:

    是的,可以像 Visual Studio 那样使用 mlaunch 工具。它仍然是封闭源代码,但通过阅读其帮助页面和 xamarin-macios 代码。不需要 IPA 构建,只需构建调试环境,使用 mlaunch 将应用程序安装到模拟器/设备并随后运行它。

    示例:在 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
    

    当命令执行时,您应该会看到按回车键终止应用程序消息

    解释

    1. msbuild /t:Build

    2. 找到mlaunch 通常在/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mlaunch。只需找到您的 Xamarin.iOS.framework 路径

    3. 列出所有可用的模拟器及其运行时和设备类型值

    mlaunch --listsim simulators.xml
    

    打开输出文件simulators.xml并选择一个模拟器,即iPhone XR,保留SimRuntimeSimDeviceType的值以供下一步使用

    1. 安装调试 Xamarin.iOS 应用程序包并在模拟器上启动
    mlaunch --launchsim=[IOS_APP_PATH] --device::v2:runtime=[SimRuntime],devicetype=[SimDeviceType]
    
    • --launchsim 是第一步中由 msbuild 任务构建的 Xamarin.iOS 应用程序包的相对路径,通常为 bin/iPhoneSimulator/Debug/IOS_PROJECT_NAME.app
    • --device 由您从 XML 文件中获得的 SimRuntime 和 SimDeviceType 组成。

    【讨论】:

    【解决方案2】:

    您正在寻找simctl 命令,它可以通过xcrun 助手获得。你可以创建、启动、关闭模拟器设备,一旦“启动”,你可以installlaunch你的iOS .app

    xcrun simctl
    usage: simctl [--set <path>] [--profiles <path>] <subcommand> ...
           simctl help [subcommand]
    Command line utility to control the Simulator
    
    For subcommands that require a <device> argument, you may specify a device UDID
    or the special "booted" string which will cause simctl to pick a booted device.
    If multiple devices are booted when the "booted" device is selected, simctl
    will choose one of them.
    
    Subcommands:
        create              Create a new device.
        clone               Clone an existing device.
        upgrade             Upgrade a device to a newer runtime.
        delete              Delete a device or all unavailable devices.
        pair                Create a new watch and phone pair.
        unpair              Unpair a watch and phone pair.
        pair_activate       Set a given pair as active.
        erase               Erase a device's contents and settings.
        boot                Boot a device.
        shutdown            Shutdown a device.
        rename              Rename a device.
        getenv              Print an environment variable from a running device.
        openurl             Open a URL in a device.
        addmedia            Add photos, live photos, videos, or contacts to the library of a device.
        install             Install an app on a device.
        uninstall           Uninstall an app from a device.
        get_app_container   Print the path of the installed app's container
        launch              Launch an application by identifier on a device.
        terminate           Terminate an application by identifier on a device.
        spawn               Spawn a process by executing a given executable on a device.
        list                List available devices, device types, runtimes, or device pairs.
        icloud_sync         Trigger iCloud sync on a device.
        pbsync              Sync the pasteboard content from one pasteboard to another.
        pbcopy              Copy standard input onto the device pasteboard.
        pbpaste             Print the contents of the device's pasteboard to standard output.
        help                Prints the usage for a given subcommand.
        io                  Set up a device IO operation.
        diagnose            Collect diagnostic information and logs.
        logverbose          enable or disable verbose logging for a device
    

    【讨论】:

      【解决方案3】:

      我找不到上面 Tri 建议的使用 mlaunch 的选项。

      但正如上面提到的 SushiHangover,您可以在终端中运行它:

      xcrun simctl install booted Sample.iOS.app
      

      只需将Sample 替换为您的项目名称即可。 我写了一个more detailed explanation here

      另外,您可以使用它来创建构建:

      msbuild Sample.iOS/Sample.iOS.csproj /verbosity:normal /t:Rebuild /p:Platform=iPhoneSimulator /p:Configuration=Debug
      

      【讨论】:

        猜你喜欢
        • 2011-04-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-17
        • 2020-07-30
        相关资源
        最近更新 更多