目前,我正在尝试使用 Avalonia 创建一个跨平台应用程序。该应用程序的标准之一是它应该在后台运行且没有 Dock 图标。当我使用 TFM
net7.0-macos
发布 MacOS 项目并从中创建 .app 包时,我遇到了一个问题:应用程序启动时,LSUIElement
中的 Info.plist
键被忽略。所有其他键均有效;例如,应用程序的名称按照 Info.plist
中的定义显示,而不是按照 app.axaml 中的设置显示。 LSUIPresentationMode
键也有作用,所以Info.plist
有故障或未加载不是问题。
这是 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>
并且这里是测试存储库的链接:
我已经尝试将
LSUIElement
设置为 string
至 1
或默认设置为 Boolean
至 true
。此外,我正在寻找其他方法来隐藏 Dock 图标。
我非常感谢您的帮助!
Avalonia Native 部分覆盖 Info.plist,因此它会在启动时重置值Avalonia Native。
可以通过将此值设置为 false 来绕过此问题。这是通过将此值添加到 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});
}