Currently, I am trying to create a cross-platform app with Avalonia. One criterion of the app is that it should run in the background without a Dock icon. When I publish the MacOS project with the TFM net7.0-macos
and create a .app bundle from it, I encounter an issue where the LSUIElement
key in Info.plist
is ignored when the app starts. All other keys have an effect; for example, the app's name is displayed as defined in Info.plist
and not as set in app.axaml. The LSUIPresentationMode
key also has an effect, so it's not a problem with the Info.plist
being faulty or not loaded.
Here is the content of the Info.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIconFile</key>
<string>car.icns</string>
<key>CFBundleIdentifier</key>
<string>com.identifier</string>
<key>CFBundleName</key>
<string>NameFromPList</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>LSMinimumSystemVersion</key>
<string>10.12</string>
<key>CFBundleExecutable</key>
<string>Plist.Desktop</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleDisplayName</key>
<string>Test</string>
<key>LSUIElement</key>
<true/>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTXcode</key>
<string>1500</string>
</dict>
</plist>
And here is the link to the test repository:
I have already tried setting LSUIElement
as a string
to 1
or as a Boolean
to true
by default. Additionally, I am looking for other ways to hide the Dock icon.
I am grateful for any assistance!
Avalonia Native partially overrides the Info.plist, so it resets the values on startup Avalonia Native.
This can be bypassed by setting this value to false. This is achieved by adding this value to the AppBuilder.
class Program {
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace()
.UseReactiveUI()
.With(new MacOSPlatformOptions() { ShowInDock = false});
}