You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 8.0-iOS项目迁移VS Code适配iOS 18遇链接错误求助

.NET 8 iOS项目迁移到VS Code后模拟器构建出现架构不匹配链接错误

问题背景

我有一个基于Visual Studio for Mac 2022的.NET 8.0-iOS项目,原本支持iOS 17。从4月起需要用最新Xcode 16生成适配iOS 18的App Store构建包,因此迁移到VS Code搭配C# Dev Kit,但构建时遇到链接错误,无法发布构建包:

最初错误(来自App Center NuGet包)

/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8319/targets/Xamarin.Shared.Sdk.targets(1648,3):
error : clang++ exited with code 1:
[/Users/Documents/Dev/NET8_PROD/S/S.iOS.csproj]

/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8319/targets/Xamarin.Shared.Sdk.targets(1648,3):
error : ld: building for 'iOS-simulator', but linking in object file
(/Users/Documents/Dev/NET8_PROD/S.iOS/obj/Debug/net8.0-ios/iossimulator-arm64/linker-cache/AppCenter.a[arm64]2)
built for 'iOS'

[/Users/Documents/Dev/NET8_PROD/S.iOS/S.iOS.csproj]
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8319/targets/Xamarin.Shared.Sdk.targets(1648,3):
error : clang++: error: linker command failed with exit code 1 (use -v
to see invocation) [/Users/Documents/Dev/NET8_PROD/S.iOS/S.iOS.csproj]

移除App Center后错误(来自Google Maps NuGet包)

/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8319/targets/Xamarin.Shared.Sdk.targets(1648,3):
error : ld: building for 'iOS-simulator', but linking in object file
(/Users/Library/Caches/XamarinBuildDownload/GMps-6.0.1/Maps/Frameworks/GoogleMaps.framework/GoogleMaps)
built for 'iOS' [/Users/Documents/Dev/NET8_PROD/S.iOS/S.iOS.csproj]

补充信息

  • 当前在Apple Silicon M3 Max的模拟器上构建,VS Code和Rider均出现相同错误
  • Visual Studio for Mac 2022已停止支持,虽能运行iOS 18模拟器和真机,但无法生成符合要求的App Store构建包

解决方法

1. 更新第三方NuGet包到兼容版本

检查并升级App Center和Google Maps的NuGet包,确保它们支持.NET 8 + iOS 18 + Apple Silicon模拟器:

  • 对于Google Maps:替换为最新版的Xamarin.Google.iOS.Maps,确认包内包含iOS模拟器(arm64)的二进制架构
  • 对于App Center:更新到最新版的Microsoft.AppCenter.Analytics、Microsoft.AppCenter.Crashes等系列包,验证是否适配iOS 18的模拟器构建

2. 明确指定模拟器构建架构

在项目的.csproj文件中添加以下配置,强制指定模拟器的架构为arm64,避免与真机架构混淆:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|iPhoneSimulator'">
  <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
  <MtouchArch>arm64</MtouchArch>
</PropertyGroup>

3. 清理构建缓存

彻底清理旧的构建缓存和第三方库下载文件,避免残留的不兼容二进制:

  • 删除项目根目录下的obj和bin文件夹
  • 删除缓存目录:/Users/Library/Caches/XamarinBuildDownload(Google Maps的缓存文件在此)
  • 运行命令行清理并恢复依赖:
    dotnet clean
    dotnet restore
    

4. 验证Xcode与.NET iOS SDK的版本匹配

确保Xcode 16已正确安装,且系统默认Xcode指向正确路径:

  • 检查当前Xcode路径:
    xcode-select -p
    
  • 如果指向旧版本,切换到Xcode 16:
    sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
    
  • 确认使用的Microsoft.iOS.Sdk版本是适配Xcode 16的(当前用的18.0.8319对应iOS 18,可检查NuGet是否有更新补丁版本)

5. 调整链接器行为

尝试将链接器设置为仅链接框架SDK,减少对第三方库二进制的过度处理:
在.csproj中添加:

<PropertyGroup>
  <MtouchLink>SdkOnly</MtouchLink>
</PropertyGroup>

6. 先验证真机构建

如果模拟器构建持续报错,先尝试构建真机版本:

  • 连接iOS真机,切换到Release|iPhone配置构建
  • 若真机构建正常,说明问题出在第三方库缺少模拟器架构的二进制,此时可以:
    • 手动下载包含模拟器架构的第三方库二进制,替换NuGet包中的对应文件
    • 联系第三方库官方,确认是否提供支持iOS模拟器的版本

内容的提问来源于stack exchange,提问作者Maddiee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 20:35:03