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

qncylg1j  于 11个月前  发布在  iOS
关注(0)|答案(2)|浏览(183)

在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]

字符串
我已经将构建管道设置为使用macos-latest,但似乎没有安装Xcode 15。
注:我在工作中遇到了这个问题,并解决了它,所以我将在下面包括我的答案。

ia2d9nvy

ia2d9nvy1#

截至2023年12月,macos-latest映像为Mac OS 12。生成代理及其映像名称的列表为documented here,列表中的生成代理沿着
相关图像名称的快速屏幕截图:x1c 0d1x

Step 1 -使用 * 实际 * 最新镜像macos-13

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

pool:
  vmImage: "macos-13"

字符串

Step 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


输出示例:

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

sxpgvts3

sxpgvts32#

此解决方案有效地确保在构建过程中使用正确的Xcode版本15.0.1,允许您的.NET 8 iOS MAUI应用程序编译,而不会遇到与旧版iOS SDK中不可用类型相关的错误。

trigger:
  branches:
    include:
      - develop

variables:
    BuildConfiguration: Release
    DotNetVersion: 8.x
    iOSVersion: net8.0-ios

pool:
  vmImage: "macos-13"
  demands: xcode

steps:
- task: PowerShell@2
  displayName: Select Xcode Version
  inputs:
    targetType: 'inline'
    script: |
      sudo xcode-select -s /Applications/Xcode_15.0.1.app

字符串

相关问题