DEV Community

Cover image for All about the local publishing of applications in .NET MAUI.
Serhii Korol
Serhii Korol

Posted on

All about the local publishing of applications in .NET MAUI.

Entry

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.

Discover project

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> -->
Enter fullscreen mode Exit fullscreen mode

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, net7.0-tizen, was commented on. Later I'll explain why.

First group

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.

Android

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
Enter fullscreen mode Exit fullscreen mode

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 .apk file.

Android

IOS

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 
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

Mac OS

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
Enter fullscreen mode Exit fullscreen mode

And finally you'll get .pkg file.

Mac

If you'll run it, you'll see installation window.

install

Second group

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
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

By the way, you might have noticed that I set p:WindowsPackageType=None parameter. It needs if you want to generate a .exe file.

Third group

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.

packages

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';
Enter fullscreen mode Exit fullscreen mode

After you do it, you can uncomment the Tizen target framework.

 <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> 
Enter fullscreen mode Exit fullscreen mode

Next put the command for publishing:

dotnet publish -f net7.0-tizen -c Release
Enter fullscreen mode Exit fullscreen mode

After several seconds, yes publishing is very fast, you'll get a .tpk file. Unlike iOS here generated default certificates.

tizen

Conclusion

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.

Buy Me A Beer

Top comments (0)