如何在 Azure DevOps 中使用 Xcode 15 构建我的 .NET 8 MAUI iOS 应用程序?

C. *_*alt 1 xcode ios azure-devops maui .net-8.0

在 Azure DevOps 构建管道中构建我的 .NET 8 iOS MAUI 应用程序时,它抱怨我没有使用最新的 Xcode。

        
ILLink : iOS error IL7000: An error occured while executing the custom linker steps. Please review the build log for more information. [/Users/runner/work/1/s/MyProject/MyProject.csproj::TargetFramework=net8.0-iOS]
/Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/UIKit/UIApplication.g.cs(95): error MT4162: The type 'UIKit.UISceneSessionActivationRequest' (used as a parameter in UIKit.UIApplication.ActivateSceneSession) is not available in iOS 16.4 (it was introduced in iOS 17.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode). [/Users/runner/work/1/s/MyProject/MyProject.csproj::TargetFramework=net8.0-iOS]
        
ILLINK : error MT2362: The linker step 'Registrar' failed during processing: The type 'UIKit.UISceneSessionActivationRequest' (used as a parameter in UIKit.UIApplication.ActivateSceneSession) is not available in iOS 16.4 (it was introduced in iOS 17.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode). [/Users/runner/work/1/s/MyProject/MyProject.csproj::TargetFramework=net8.0-iOS]       
Run Code Online (Sandbox Code Playgroud)

我已设置要使用的构建管道,macos-latest但 Xcode 15 似乎未安装。

注意:我在工作中遇到了这个问题并已解决,因此我将在下面包含我的答案。

C. *_*alt 6

截至 2023 年 12 月,macos-latest映像为 Mac OS 12。构建代理列表及其映像名称记录在此处

此处相关图像名称的快速屏幕截图: 在此输入图像描述

第 1 步 - 使用实际的最新图像macos-13

目前它处于预览状态,但它安装了最新版本的 Xcode(15.0 和 15.0.1)。

pool:
  vmImage: "macos-13"
Run Code Online (Sandbox Code Playgroud)

第 2 步 - 选择 Xcode 版本

我的构建管道中有一些 yaml,列出了相关信息并选择我想要使用的最新版本的 Xcode。

  - script: |
     echo Mac OS version:
     sw_vers -productVersion
     echo
     echo Installed Xcode versions:
     ls /Applications | grep 'Xcode'
     echo
     echo currently selected xcode:
     xcrun xcode-select --print-path
     echo
     echo selecting latest xcode...
     sudo xcode-select -s /Applications/Xcode_15.0.1.app
     xcrun xcode-select --print-path
     xcodebuild -version
    displayName: Select Xcode Version
Run Code Online (Sandbox Code Playgroud)

输出示例:

Starting: Select Xcode Version
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.231.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /Users/runner/work/_temp/bb313650-3256-4f80-b567-0ec926cb9c07.sh
Mac OS version:
13.6

Installed Xcode versions:
Xcode.app
Xcode_14.1.0.app
Xcode_14.1.app
Xcode_14.2.0.app
Xcode_14.2.app
Xcode_14.3.1.app
Xcode_14.3.app
Xcode_15.0.1.app
Xcode_15.0.app

currently selected xcode:
/Applications/Xcode_14.3.1.app/Contents/Developer

selecting latest xcode...
/Applications/Xcode_15.0.1.app/Contents/Developer
Xcode 15.0.1
Build version 15A507
Finishing: Select Xcode Version
Run Code Online (Sandbox Code Playgroud)