Chris
Chris

Reputation: 545

Errors with dotnet publish

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?

Upvotes: 6

Views: 7875

Answers (3)

Mr. Horse
Mr. Horse

Reputation: 116

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.

Upvotes: 0

Duy Lan Le
Duy Lan Le

Reputation: 298

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!

Upvotes: 4

ToolmakerSteve
ToolmakerSteve

Reputation: 21358

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>

Upvotes: 0

Related Questions