我使用了这些资源来学习如何发布MAUI应用程序:
https://learn.microsoft.com/en-us/dotnet/maui/ios/deployment/overview
https://github.com/dotnet/maui/issues/4397
https://github.com/dotnet/sdk/issues/21877
基于这些,我尝试了不同的变体来发布,但它们都没有工作:
dotnet publish -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 错误: RuntimeIdentifier 'ios-arm64‘无效。
dotnet publish -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 --no-restore错误NETSDK1032: RuntimeIdentifier平台'ios-arm64‘和PlatformTarget 'x64’必须兼容。
dotnet build -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 /p:BuildIpa=true错误: RuntimeIdentifier 'ios-arm64‘无效。
dotnet build -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 /p:BuildIpa=true --no-restore错误NETSDK1032: RuntimeIdentifier平台'ios-arm64‘和PlatformTarget 'x64’必须兼容。
更新
环境:
Windows 10家庭- 21H2
VS 2022版本17.3.0预览1.1
更新2
根据我现在得到的答案,csproj文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0-ios</TargetFrameworks>
<OutputType>Exe</OutputType>
<RootNamespace>MonkeyFinder</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Display name -->
<ApplicationTitle>MonkeyFinder</ApplicationTitle>
<!-- App Identifier -->
<ApplicationId>com.testapp.monkeyfinder</ApplicationId>
<ApplicationIdGuid>E46570A0-D087-4FC2-ADFE-58FEAB0BEBB9</ApplicationIdGuid>
<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<!-- Required for C# Hot Reload -->
<UseInterpreter Condition="'$(Configuration)' == 'Debug'">True</UseInterpreter>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
<CodesignKey>xxx</CodesignKey>
<CodesignProvision>Development Test Provisioning</CodesignProvision>
<ArchiveOnBuild>true</ArchiveOnBuild>
<TcpPort>58181</TcpPort>
<ServerAddress>xxx</ServerAddress>
<ServerUser>xxx</ServerUser>
<ServerPassword>xxx</ServerPassword>
<_DotNetRootRemoteDirectory>/Users/xxx/Library/Caches/Xamarin/XMA/SDKs/dotnet/</_DotNetRootRemoteDirectory>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-android|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-android|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-ios|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-ios|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-maccatalyst|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-maccatalyst|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-windows10.0.19041|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-windows10.0.19041|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\appicon.svg" ForegroundFile="Resources\appiconfg.svg" Color="#512BD4" />
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" />
<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>然后,我根据更多收集到的信息试用了这些命令,结果如下:
dotnet publish -f:net6.0-ios -c:Release必须指定设备体系结构的运行时标识符才能发布此项目。‘ios仿真器-x64’是一个仿真器架构。
dotnet build -c:Release /p:BuildIpa=true成功,但bin/Release/net6.0-IOS/iOSarm64/ *.ipa文件中没有任何ios文件
我还删除了其他的PropertyGroup标记,但是没有什么区别。当移除第一个错误时,错误是:
错误NETSDK1013: TargetFramework值'‘未被识别。可能拼错了。如果没有,则必须显式地指定TargetFrameworkIdentifier和/或TargetFrameworkVersion属性。
而且这个项目已经不能正常加载了。
更新3:
当我从模板创建一个全新的.NET MAUI项目时,它将使用以下命令进行编译
dotnet publish -f:net6.0-ios -c:Release但是,即使当我将csproj文件中的xml从工作项目复制到不工作项目时,我也会得到错误:
必须指定设备体系结构的运行时标识符才能发布此项目。‘ios仿真器-x64’是一个模拟器
我猜这表明错误的原因实际上不是在csproj文件中,而是在其他地方?
发布于 2022-06-15 20:04:50
我的解决方案是在Mac上运行它。不要在你的窗口机器上运行它。
目前,您可能希望安装项目的Mac和Open终端的Visual 2022预览。然后,使用sudo运行该命令。
示例:
sudo dotnet publish -f:net6.0-ios -c:Release注意:我在毛伊岛项目中用PropertyGroup设置了我的所有属性
像个冠军一样工作!
发布于 2022-05-27 02:21:05
FIX 1
尝试通过RuntimeIdentifier中的条件属性组包括.csproj,从命令行中省略。
来自添加代码签名..。。
.csproj:
<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
<CodesignKey>iPhone Distribution: John Smith (AY2GDE9QM7)</CodesignKey>
<CodesignProvision>MyMauiApp</CodesignProvision>
<ArchiveOnBuild>true</ArchiveOnBuild>
</PropertyGroup>命令行:
dotnet publish -f:net6.0-ios -c:ReleaseFIX 2
现在,当发布到ios时,将其他目标框架从.csproj中删除。注意:这不应该是必需的,因为您通过-f指定了框架,但是值得一试。
更改:
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>至:
<TargetFrameworks>net6.0-ios</TargetFrameworks>https://stackoverflow.com/questions/72399444
复制相似问题