Azure DevOps publish fails for MAUI.NET iOS

Milad Xandi 0 Reputation points
2025-07-02T20:42:25.2366667+00:00

This is part of my Azure Pipeline:

       - task: Bash@3

            displayName: Install MAUI

            inputs:

              targetType: 'inline'

              script: |

                dotnet workload update

                dotnet workload install maui android ios wasm-tools --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json --source https://api.nuget.org/v3/index.json

          - task: Bash@3

            displayName: Nuget Restorations

            inputs:

              targetType: 'inline'

              script: |

                dotnet restore $(app-name).sln --runtime ios-arm64 -p:TargetFramework=net9.0-ios \

                --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json \

                --source https://api.nuget.org/v3/index.json

          - script: |

              dotnet publish -f net9.0-ios -c Release -r ios-arm64 --no-restore \

                -p:PlatformTarget=arm64 \

                -p:CodesignKey="$(identity)" \

                -p:CodesignProvision="$(profile-name)" \

                -p:ApplicationVersion="$(build-number64)" \

                -p:CodesignTeamId="$(team)" \

                -p:OutputPath=$(Build.ArtifactStagingDirectory)/publish \

            displayName: 'Build & Publish iOS'

This is part of my .csproj file:

<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios' And '$(Configuration)' == 'Release'">

        <ApplicationId>******</ApplicationId>

        <PlatformTarget>arm64</PlatformTarget>

        <SupportedOrientations>Portrait</SupportedOrientations>

        <BuildIpa>False</BuildIpa>

        <IpaIncludeArtwork>True</IpaIncludeArtwork>

        <IpaPackageName>*****</IpaPackageName>

        <CodesignEntitlements>Platforms\iOS\Entitlements.plist</CodesignEntitlements>

        <CodesignKey>*****</CodesignKey>

        <CodesignProvision>*****</CodesignProvision>

        <EnableAssemblyILStripping>False</EnableAssemblyILStripping>

        <MtouchDebug>False</MtouchDebug>

        <MtouchLink>None</MtouchLink>

        <MtouchUseLlvm>False</MtouchUseLlvm>

        <MtouchExtraArgs>--none</MtouchExtraArgs>

        <MtouchInterpreter>False</MtouchInterpreter>

        <RunAOTCompilation>False</RunAOTCompilation>

        <Optimize>False</Optimize>

        <IsTrimmable>False</IsTrimmable>

    </PropertyGroup>

If I set PublishTrimmed to True Or leave it Empty even with 'MtouchLink=None' It will cancel the job:

Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink

Optimizing assemblies for size. This process might take a while.

##[error]The Operation will be canceled. The next steps may not contain expected logs.

##[error]The operation was canceled.

Because of this error:

The job running on agent Hosted Agent ran longer than the maximum time of 60 minutes. For more information, see https://go.microsoft.com/fwlink/?linkid=207713420250702.3|
The Operation will be canceled. The next steps may not contain expected logs.Build & Publish iOS
The Operation will be canceled. The next steps may not contain expected logs.Build & Publish iOS
The operation was canceled. Build & Publish iOS

Or if I set it to False It will give me this error:

error : iOS projects must build with PublishTrimmed=true. Current value: False. Set 'MtouchLink=None' instead to disable trimming for all assemblies. rk=net9.0-ios]

##[error]Bash exited with code '1'. ts(306,3):

What should I do exactly?!

Developer technologies | .NET | .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. Harry Vo (WICLOUD CORPORATION) 1,315 Reputation points Microsoft External Staff
    2025-08-27T08:37:24.1266667+00:00

    Hi @Milad Xandi , thank you for reaching out on Microsoft Q&A!

    On iOS, trimming is required by the platform, and Apple requires apps to be fully linked. If you try to set <PublishTrimmed>false</PublishTrimmed>, the build will explicitly fail. In other words, trimming is expected and not related to the cancellation.

    The real problem is the cancellation during dotnet publish, and there are many possible causes for this issue.

    There's a case relate to your issue that I believe can help you on this. He had a practical workaround which is to force a single-threaded publish by adding -m:1 to your dotnet publish command:

    dotnet publish -m:1 -f net9.0-ios -c Release -r ios-arm64 \
      -p:PlatformTarget=arm64 \
      -p:CodesignKey="$(identity)" \
      -p:CodesignProvision="$(profile-name)" \
      -p:CodesignTeamId="$(team)" \
      -p:OutputPath="$(Build.ArtifactStagingDirectory)/publish"
    
    

    Moreover, make sure your build agent is using an Xcode version that matches the requirements of the microsoft.net.sdk.ios workload you have installed. For .NET 9 builds, Xcode 16.3 or later is typically required.

    I hope this helps you get things back on track quickly! If my suggestions can solve your issue, feel free to interact with the system accordingly!

    Thank you!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.