In this article, I want to talk about publishing MAUI applications locally. I'll show from non-Windows OS, and we'll be published for different platforms. I'll dwell in detail on each platform, and we'll find out with pitfalls for them. I'll demonstrate on MAC OS, and I'll ask you to take it into account. Let's go.
First of all, create a simple MAUI project from a template. We'll be using it as an example for publishing.
If you'll find the
.proj file and edit it, you are able to see supported platforms.
<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks> <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks> <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET --> <!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
As you might have noticed that target frameworks are divided into three groups. First group
net7.0-android, net7.0-ios, net7.0-maccatalyst. Second group
net7.0-windows10.0.19041.0. And finally, the third group, n
et7.0-tizen, was commented on. Later I'll explain why.
By default, you are able to run applications only for Android, IOS, and Mac OS. However, for Android you need to download SDK and desired OS version.
For Android, as was mentioned, it needs SDK. If you already have it then let's go to the command line of your solution. For publishing you not need anything else, only run this command:
dotnet publish -f net7.0-android -c Release
The framework name is the same as that was shown in the project file.
If you'll get to the Release folder in your project, you'll see generated
With iOS, everything is more problematic. Apple Inc doesn't permit publishing applications without developer certificates. Otherwise, you'll get an error. But anyway, I'll show the command for publishing. It is a little bit different than Android. You need set architecture in parameters.
dotnet publish -f net7.0-ios -c Release -r ios-arm64
And if you don't have a certificate you'll get an error:
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/16.4.7089/tools/msbuild/iOS/Xamarin.Shared.targets(1714,3): error : No valid iOS code signing keys found in keychain. You need to request a codesigning certificate from https://developer.apple.com. [/Users/serhiikorol/RiderProjects/MauiApp1/MauiApp1/MauiApp1.csproj::TargetFramework=net7.0-ios] /usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/16.4.7089/tools/msbuild/iOS/Xamarin.Shared.targets(1714,3): error : [/Users/serhiikorol/RiderProjects/MauiApp1/MauiApp1/MauiApp1.csproj::TargetFramework=net7.0-ios]
The easiest OS is Mac OS. You do not need to install additional SDK, and main, you do not need any certificates, just put this command:
dotnet publish -f net7.0-maccatalyst -c Release
And finally you'll get
If you'll run it, you'll see installation window.
The Windows platform was removed to a separate group. It needs because Windows application you can publish only from Windows OS. This condition checks current OS
$([MSBuild]::IsOSPlatform('windows')). Sure, you can run it from Mac OS:
dotnet publish -f net7.0-windows10.0.19041.0 -c Release -p:WindowsPackageType=None
Sure you'll get an error that you don't have Windows:
/usr/local/share/dotnet/sdk/7.0.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): error NETSDK1100: To build a project targeting Windows on this operating system, set the EnableWindowsTargeting property to true. [/Users/serhiikorol/RiderProjects/MauiApp1/MauiApp1/MauiApp1.csproj::TargetFramework=net7.0-windows10.0.19041.0]
By the way, you might have noticed that I set
p:WindowsPackageType=None parameter. It needs if you want to generate a
Tizen also was removed to a separate group and even commented on why you'll ask me. Since Tizen is not supported from the box. You need to install an additional SDK.
The first step is to download Tizen Studio by this link. It supports Windows, Linux, and Mac OS. When installing IDE, run package manager and install packages for the chosen platform. I selected the latest mobile platform.
Second step you need install the workload packages:
#Mac OS and linux curl -sSL https://raw.githubusercontent.com/Samsung/Tizen.NET/main/workload/scripts/workload-install.sh | sudo bash #windows PS D:\workspace> Invoke-WebRequest 'https://raw.githubusercontent.com/Samsung/Tizen.NET/main/workload/scripts/workload-install.ps1' -OutFile 'workload-install.ps1';
After you do it, you can uncomment the Tizen target framework.
Next put the command for publishing:
dotnet publish -f net7.0-tizen -c Release
After several seconds, yes publishing is very fast, you'll get a
.tpk file. Unlike iOS here generated default certificates.
MAUI allows you to develop applications for 5 platforms and have only one application. However, if you use a non-Windows platform, you'll face with some restrictions for the Windows platform. And also, I want to say for Tizen you can use only Visual Studio, the Rider doesn't support this platform.
Thank you for reading, making a subscription, putting likes, and happy coding.