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

Xamarin Forms迁移MAUI:iOS项目RuntimeIdentifiers配置报错NETSDK1083

问题描述

将Xamarin Forms项目迁移至.NET MAUI时,修改iOS项目的.csproj文件,按照官方文档把MtouchArch替换为RuntimeIdentifiers,并将原有的i386、x86_64替换为iossimulator-x86、iossimulator-x64。删除bin和obj目录恢复NuGet包时,出现错误:

/usr/local/share/dotnet/sdk/7.0.304/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5) : error NETSDK1083: The specified RuntimeIdentifier 'iossimulator-x64,iossimulator-x86' is not recognized.

原Xamarin配置:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugUAT|iPhoneSimulator' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\iPhone\Debug</OutputPath>
    <DefineConstants>__UNIFIED__;__MOBILE__;__IOS__;__UNIFIED__;__MOBILE__;__IOS__;DEBUG;DISABLE_PINNING</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <ConsolePause>false</ConsolePause>
    <CodesignKey>iPhone Developer</CodesignKey>
    <DeviceSpecificBuild>true</DeviceSpecificBuild>
    <MtouchDebug>true</MtouchDebug>
    <MtouchFastDev>true</MtouchFastDev>
    <MtouchFloat32>true</MtouchFloat32>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <MtouchLink>SdkOnly</MtouchLink>
    <MtouchArch>i386, x86_64</MtouchArch>
    <MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
    <MtouchTlsProvider>Default</MtouchTlsProvider>
    <MtouchExtraArgs>-cxx -gcc_flags "-L${ProjectDir} -framework Security -framework AudioToolbox -liconv -lc++" --optimize=force-rejected-types-removal --warn-on-type-ref=UIKit.UIWebView -warnaserror:1503</MtouchExtraArgs>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <CodesignProvision>
    </CodesignProvision>
</PropertyGroup>

迁移后的MAUI配置:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugUAT|AnyCPU' ">
    <DefineConstants>DEBUG</DefineConstants>
    <Platforms>x86</Platforms>
    <RuntimeIdentifiers>iossimulator-x86,iossimulator-x64</RuntimeIdentifiers>
    <DefineConstants>__UNIFIED__;__MOBILE__;__IOS__;DEBUG;MOCK_API</DefineConstants>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\iPhone\Debug</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <ConsolePause>false</ConsolePause>
    <CodesignKey>iPhone Developer</CodesignKey>
    <DeviceSpecificBuild>true</DeviceSpecificBuild>
    <MtouchDebug>true</MtouchDebug>
    <MtouchFastDev>true</MtouchFastDev>
    <MtouchFloat32>true</MtouchFloat32>
    <MtouchLink>SdkOnly</MtouchLink>
    <MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
    <MtouchTlsProvider>Default</MtouchTlsProvider>
    <MtouchExtraArgs>-cxx -gcc_flags "-L${ProjectDir} -framework Security -framework AudioToolbox -liconv -lc++" --optimize=force-rejected-types-removal --warn-on-type-ref=UIKit.UIWebView -warnaserror:1503</MtouchExtraArgs>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <CodesignProvision>
    </CodesignProvision>
</PropertyGroup>
解决方案

1. 修正RuntimeIdentifiers的格式与有效值

  • .NET SDK要求多个RuntimeIdentifier之间用**分号;**分隔,而非逗号,逗号会被识别为单个RuntimeIdentifier的一部分,直接导致识别失败。
  • iossimulator-x86对应老旧的32位iOS模拟器,现代.NET SDK已不再支持该架构,可移除;若使用Apple Silicon Mac,需添加iossimulator-arm64适配原生模拟器架构。

修改后的配置:

<RuntimeIdentifiers>iossimulator-x64;iossimulator-arm64</RuntimeIdentifiers>

2. 匹配正确的平台条件

原Xamarin配置的平台是iPhoneSimulator,迁移后误改为AnyCPU,导致平台上下文不匹配,需改回:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugUAT|iPhoneSimulator' ">

3. 清理冗余与错误配置

  • 移除重复的<CodesignEntitlements>节点
  • 将<Platforms>修正为对应有效架构:x64;arm64,而非单一的x86
  • 合并重复的<DefineConstants>节点,保留完整的常量定义

最终修正后的PropertyGroup配置

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugUAT|iPhoneSimulator' ">
    <DefineConstants>__UNIFIED__;__MOBILE__;__IOS__;DEBUG;MOCK_API</DefineConstants>
    <Platforms>x64;arm64</Platforms>
    <RuntimeIdentifiers>iossimulator-x64;iossimulator-arm64</RuntimeIdentifiers>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\iPhone\Debug</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <ConsolePause>false</ConsolePause>
    <CodesignKey>iPhone Developer</CodesignKey>
    <DeviceSpecificBuild>true</DeviceSpecificBuild>
    <MtouchDebug>true</MtouchDebug>
    <MtouchFastDev>true</MtouchFastDev>
    <MtouchFloat32>true</MtouchFloat32>
    <MtouchLink>SdkOnly</MtouchLink>
    <MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
    <MtouchTlsProvider>Default</MtouchTlsProvider>
    <MtouchExtraArgs>-cxx -gcc_flags "-L${ProjectDir} -framework Security -framework AudioToolbox -liconv -lc++" --optimize=force-rejected-types-removal --warn-on-type-ref=UIKit.UIWebView -warnaserror:1503</MtouchExtraArgs>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <CodesignProvision>
    </CodesignProvision>
</PropertyGroup>

后续操作

  1. 保存修改后的.csproj文件
  2. 再次删除bin和obj目录
  3. 执行dotnet restore恢复NuGet包,或在IDE中重新加载项目触发恢复

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 18:15:00