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

Maui iOS模拟器构建失败:需添加iossimulator-x64至RuntimeIdentifiers

问题:M3 Mac上iOS模拟器无法运行MAUI项目,报NETSDK1047错误

运行项目时触发以下错误:

/usr/local/share/dotnet/sdk/8.0.302/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(5,5): Error NETSDK1047: Assets file '/Users/ragib.noor/Repository/PMI_Service_Gateway/src/PMI.Service.Mobile.Maui/PMI.Service.Mobile.Maui.iOS/obj/project.assets.json' doesn't have a target for 'net8.0-ios/iossimulator-x64'. Ensure that restore has run and that you have included 'net8.0-ios' in the TargetFrameworks for your project. You may also need to include 'iossimulator-x64' in your project's RuntimeIdentifiers. (NETSDK1047) (PMI.Service.Mobile.Maui.iOS)

项目仅针对iOS运行时,配置如下:

<PropertyGroup>
    <TargetFramework>net8.0-ios</TargetFramework>
    <SupportedOSPlatformVersion>14.0</SupportedOSPlatformVersion>
    <OutputType>Exe</OutputType>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseMaui>true</UseMaui>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'">
    <CreatePackage>false</CreatePackage>
    <BuildIpa>true</BuildIpa>
    <IpaMetadata>info.plist</IpaMetadata>
    <IpaPackageName>****</IpaPackageName>
    <CodesignKey>*****</CodesignKey>
    <CodesignProvision>****</CodesignProvision>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <UseNativeHttpHandler>false</UseNativeHttpHandler>
    <MtouchExtraArgs>-v -v -v -v --dlsym:Microsoft.Win32.Registry.dll</MtouchExtraArgs>
    <MtouchLink>SdkOnly</MtouchLink>
    <OptimizePNGs>false</OptimizePNGs>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-ios|AnyCPU'">
    <CreatePackage>false</CreatePackage>
    <BuildIpa>true</BuildIpa>
    <IpaMetadata>info.plist</IpaMetadata>
    <CodesignProvision>******</CodesignProvision>
    <CodesignKey></CodesignKey>
    <IpaPackageName></IpaPackageName>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
</PropertyGroup>

已尝试操作:

  • 清理bin/obj文件夹
  • 还原NuGet包
  • 多次重启IDE

环境信息:

Visual Studio Community 2022 for Mac
Version 17.6.12 (build 410)
Installation UUID: 77a4961a-16b0-4d71-867b-366b473d86b3

Runtime
.NET 7.0.3 (64-bit)
Architecture: Arm64
Microsoft.macOS.Sdk 13.1.1007; git-rev-head:8afca776a0a96613dfb7200e0917bb57f9ed5583; git-branch:release/7.0.1xx-xcode14.2

Roslyn (Language Service)
4.6.0-3.23180.6+99e956e42697a6dd886d1e12478ea2b27cceacfa

NuGet
Version: 6.4.0.117

.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/8.0.302/Sdks
SDK Versions:
    8.0.302
    7.0.316
    6.0.422
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    8.0.6
    7.0.19
    6.0.30

Xamarin.Profiler
Version: 1.8.0.49
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Apple Developer Tools
Xcode: 15.2 22503
Build: 15C500b

Xamarin.Mac
Version: 9.3.0.23 Visual Studio Community
Hash: 9defd91b3
Branch: xcode14.3
Build date: 2023-10-23 16:14:59-0400

Xamarin.iOS
Version: 16.4.0.23 Visual Studio Community
Hash: 9defd91b3
Branch: xcode14.3
Build date: 2023-10-23 16:15:00-0400

Xamarin Designer
Version: 17.6.3.9
Hash: 2648399ae8
Branch: remotes/origin/d17-6
Build date: 2024-05-09 04:36:07 UTC

Xamarin.Android
Version: 13.2.2.0 (Visual Studio Community)
Commit: xamarin-android/d17-5/45b0e14
Android SDK: /Users/ragib.noor/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        13.0 (API level 33)

SDK Command-line Tools Version: 7.0
SDK Platform Tools Version: 34.0.3
SDK Build Tools Version: 32.0.0

Build Information: 
Mono: d9a6e87
Java.Interop: xamarin/java.interop/d17-5@149d70fe
SQLite: xamarin/sqlite/3.40.1@68c69d8
Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.16.1

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302

Android SDK Manager
Version: 17.6.0.50
Hash: a715dca
Branch: HEAD
Build date: 2024-05-09 04:36:12 UTC

Android Device Manager
Version: 0.0.0.1309
Hash: 06e3e77
Branch: HEAD
Build date: 2024-05-09 04:36:12 UTC

Build Information
Release ID: 1706120410
Git revision: 2f8e0518dd80a933901821bac53f7398d4b61c0f
Build date: 2024-05-09 04:34:23+00
Build branch: release-17.6
Build lane: release-17.6

Operating System
Mac OS X 14.5.0
Darwin 23.5.0 Darwin Kernel Version 23.5.0
    Wed May  1 20:17:33 PDT 2024
    root:xnu-10063.121.3~5/RELEASE_ARM64_T6031 arm64

注:相同配置在Intel Mac可正常运行,当前在M3 Mac尝试运行。


解决步骤

1. 添加Arm64模拟器运行时标识

M3 Mac为Arm架构,需在项目根PropertyGroup中添加适配的运行时标识:

<PropertyGroup>
    <TargetFramework>net8.0-ios</TargetFramework>
    <SupportedOSPlatformVersion>14.0</SupportedOSPlatformVersion>
    <OutputType>Exe</OutputType>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseMaui>true</UseMaui>
    <!-- 添加Arm64模拟器、真机及兼容x64的运行时标识 -->
    <RuntimeIdentifiers>iossimulator-arm64;ios-arm64;iossimulator-x64</RuntimeIdentifiers>
</PropertyGroup>

2. 调整Debug配置的Platform目标

将Debug配置的Platform从AnyCPU改为Arm64,匹配M3架构:

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|Arm64'">
    <CreatePackage>false</CreatePackage>
    <BuildIpa>true</BuildIpa>
    <IpaMetadata>info.plist</IpaMetadata>
    <IpaPackageName>****</IpaPackageName>
    <CodesignKey>*****</CodesignKey>
    <CodesignProvision>****</CodesignProvision>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <UseNativeHttpHandler>false</UseNativeHttpHandler>
    <MtouchExtraArgs>-v -v -v -v --dlsym:Microsoft.Win32.Registry.dll</MtouchExtraArgs>
    <MtouchLink>SdkOnly</MtouchLink>
    <OptimizePNGs>false</OptimizePNGs>
</PropertyGroup>

3. 强制清理并定向还原

在终端进入项目根目录,执行以下命令:

dotnet clean
dotnet restore -r iossimulator-arm64

4. 修复Xcode与Xamarin版本兼容性

当前Xcode 15.2与Xamarin.iOS 16.4.0.23(对应Xcode14.3)版本不匹配,需二选一:

  • 更新Visual Studio for Mac至最新版本,确保Xamarin.iOS支持Xcode15.2
  • 降级Xcode至14.3版本,匹配当前Xamarin.iOS版本

5. 选择Arm64架构模拟器

在Visual Studio的设备选择器中,选择Arm64架构的iOS模拟器(如iPhone 15系列),避免选择x64架构模拟器。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 20:35:54