5

I've used these resources to learn how to publish a MAUI app:

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

Based on these, I tried different variants to publish, but none of them work:

dotnet publish -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 

error : The RuntimeIdentifier 'ios-arm64' is invalid.

dotnet publish -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 --no-restore

error NETSDK1032: The RuntimeIdentifier platform 'ios-arm64' and the PlatformTarget 'x64' must be compatible.

dotnet build -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 /p:BuildIpa=true

error : The RuntimeIdentifier 'ios-arm64' is invalid.

dotnet build -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 /p:BuildIpa=true --no-restore

error NETSDK1032: The RuntimeIdentifier platform 'ios-arm64' and the PlatformTarget 'x64' must be compatible.

Update
Environment:
Windows 10 Home - 21H2
VS 2022 Version 17.3.0 Preview 1.1

Update 2
Based on the answers I have now this csproj file:

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

And then I tried out these commands based on more collected information since, with the following results:

dotnet publish -f:net6.0-ios -c:Release

A runtime identifier for a device architecture must be specified in order to publish this project. 'iossimulator-x64' is a simulator architecture.

dotnet build -c:Release /p:BuildIpa=true

Successful, but there is no *.ipa file in bin/Release/net6.0-ios/ios-arm64/publish

I also removed the other PropertyGroup tags, but it made no difference. Expect when removing the first one, then the error is:

error NETSDK1013: The TargetFramework value '' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly.

And also the project doesn't load properly anymore.

Update 3:
When I create a brand new .NET MAUI project from the template it starts compiling with the command

dotnet publish -f:net6.0-ios -c:Release

But even when I copy the xml in the csproj file from the working to the not working project I get the error:

A runtime identifier for a device architecture must be specified in order to publish this project. 'iossimulator-x64' is a simulator

I guess this indicates that the cause for the error is actually not to be found in the csproj file, but somewhere else?

Chris
  • 305
  • 4
  • 19
  • From Windows or Mac VS? Updated to latest VS 2022 Preview? Are you able to `build` `Debug` version from command line? (without BuildIpa) – ToolmakerSteve May 27 '22 at 01:22
  • From Windows, with the latest VS 2022 Preview. The command "dotnet build -c:Debug" works successfully. – Chris May 27 '22 at 11:49
  • Do you have multiple projects? Try publishing the csproj specifically. So dotnet publish YourProject.csproj and then the rest of the options – Gerald Versluis May 28 '22 at 15:53
  • It's only one project. I accidentally might have figured it out: I changed the tag RuntimeIdentifier to RuntimeIdentifiers, then it started to compile. But now I am stuck with the next error: "code signing key not found in keychain" – Chris May 28 '22 at 19:08
  • How the hell did u think about adding an "s"? That solved for me too! For the error you get now, you have to follow the steps https://learn.microsoft.com/en-us/dotnet/maui/ios/deployment/overview#add-code-signing-data-to-your-app-project and add the certificate to the Mac machine keychain – ScottexBoy Jun 23 '22 at 09:41
  • @ScottexBoy Be aware, that you might run into other issues when changing to plural: https://stackoverflow.com/questions/72509265/xamarin-shared-sdk-targets366-3-messagingremoteexception-aggregateexception-a – Chris Jun 23 '22 at 12:28
  • well for the runtime identifier part i dont get other errors, but now when the build process tries to optimize the assembly for file size, it makes the mac disconnect and then it times out. Doing the command to avoiding this operation doesnt work, but they say it should be fixed after preview 13 of maui. – ScottexBoy Jun 23 '22 at 14:02
  • @ScottexBoy I ran into so many errors and still am also during runtime. I can only hope, that this becomes more stable very soon. – Chris Jun 23 '22 at 14:18
  • Man i don't really know, deleting bin and obj with visual studio closed, seems to work everytime i get the "A runtime identifier for a device architecture must be specified in order to publish this project. 'iossimulator-x64' is a simulator" error, but maybe you get it everytime regardless. Then in order to publish i need to also disable the LLVM optimization or the process would hang. On a new project now i can sucessfully generate the .ipa file. On my current project now the zip cannot be unzipped to bin/release for some reason, the path is messed up and repeated. – ScottexBoy Jun 24 '22 at 09:25
  • 2
    @Chris did you manage to make it work? try deleting the user.csproj file https://stackoverflow.com/questions/72502924/error-netsdk1032-the-runtimeidentifier-platform-ios-arm64-and-the-platformtar – ScottexBoy Sep 19 '22 at 13:25

3 Answers3

2

My solution is to run it on a Mac. Don't run it on your Window machine.

At the moment, you may want to install Visual Studio 2022 Preview for Mac and Open Terminal of your project. Then, run the command with sudo.

Example:

sudo dotnet publish -f:net6.0-ios -c:Release

Note: I set all of my properties in PropertyGroup in the Maui Project

Worked like a champ!

Duy Lan Le
  • 228
  • 4
  • 11
0

FIX 1

Try including RuntimeIdentifier via a conditional property group in .csproj, and omit it from command line.

From Add code signing ....
.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>

Command line:

dotnet publish -f:net6.0-ios -c:Release

FIX 2

For now, when publish for ios, remove other target frameworks from .csproj. NOTE: This shouldn't be needed, because you specify framework via -f, but its worth a try.

Change:

<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>

To:

<TargetFrameworks>net6.0-ios</TargetFrameworks>
ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
0

Here is the YAML that worked for our build pipeline. It took me a long time to get it working, hopefully it helps saves someone some time.

- task: DotNetCoreCLI@2
    displayName: Build app and publish ipa file
    inputs:
      command: publish
      publishWebProjects: false
      projects: '**/*ProjectName.csproj'
      custom: 'publish '
      arguments: '--no-restore -r ios-arm64 -c Release -p:ArchiveOnBuild=true -p:ApplicationId=$(AppStore.CFBundleIdentifier) -p:CodesignKey=$(APPLE_CERTIFICATE_SIGNING_IDENTITY) -p:CodesignProvision=$(APPLE_PROV_PROFILE_UUID) '
      zipAfterPublish: false
      modifyOutputPath: false

This documentation should help you publish the ipa file for release. What you may have been missing are these parameters: -r ios-arm64 -p:ArchiveOnBuild=true.

Mr. Horse
  • 96
  • 9