Yes, it's possible to run WPF applications on Mac with little to no code changes using Avalonia XPF. This is possible thanks to Microsoft making WPF open-source and using a permissive license.
The common steps are as follows:
- Add a NuGet.config We can ship Avalonia XPF as a NuGet package, which requires adding our private nuget feeds to gain access. We'll do this by creating a
NuGet.config
file at the root of our solution. It'll include the following:<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <clear /> <add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" /> <add key="xpf" value="https://xpf-nuget-feed.avaloniaui.net/v3/index.json" /> <add key="avalonia-nightly" value="https://nuget-feed-all.avaloniaui.net/v3/index.json" /> </packageSources> <packageSourceCredentials> <xpf> <add key="Username" value="license" /> <add key="ClearTextPassword" value="<YOUR_LICENSE_KEY>" /> </xpf> </packageSourceCredentials> </configuration>
- Load the solution and replace the project SDK with Avalonia XPF For example:
<Project Sdk="Xpf.Sdk/1.0.1-cibuild001124">
- Update the TargetFramework Avalonia XPF requires WPF apps to target NET6 or above. For this reason, we'll update the apps Target Framework to the latest NET8 runtime.
<TargetFramework>net8.0</TargetFramework>
- Add the license key The last change is to add our license key to the
csproj
for the executable.
<ItemGroup>
<RuntimeHostConfigurationOption Include="AvaloniaUI.Xpf.LicenseKey" Value="<YOUR_LICENSE_KEY>" />
</ItemGroup>
For more information, please check: https://avaloniaui.net/blog/wpf-on-mac
To run a WPF app on Linux, you can check : A developers guide to running WPF apps on Linux with .NET Core.