macOS 部署
macOS应用程序通常以 .app 应用程序包 的形式分发。要让 .NET Core 和 Avalonia 项目在 .app 包中运行,需要在应用程序完成发布流程后进行一些额外的工作。
对于 Avalonia,您的 .app 文件夹结构如下:
MyProgram.app
|
----Contents\
|
------_CodeSignature\(存储代码签名信息)
| |
| ------CodeResources
|
------MacOS\(您的所有 DLL 文件等 -- `dotnet publish` 的输出)
| |
| ---MyProgram
| |
| ---MyProgram.dll
| |
| ---Avalonia.dll
|
------Resources\
| |
| -----MyProgramIcon.icns(图标文件)
|
------Info.plist(存储捆绑包标识符、版本等信息)
------embedded.provisionprofile(签名信息文件)
有关 Info.plist 的更多信息,请参阅苹果的文档。
创建应用程序包
有几个选项可用于创建 .app 文件/文件夹结构。您可以在任何操作系统上执行此操作,因为 .app 文件只是按照特定格式排列的一组文件夹,工具并不特定于一个操作系统。但是,如果您在 Windows 上构建(而不是在 WSL 中),可执行文件可能没有适合 macOS 上执行的正确属性 -- 您可能需要在来自 Unix 设备的已发布二进制输出(由 dotnet publish 生成的输出)上运行 chmod +x。这是最终位于文件夹 MyApp.app/Contents/MacOS/ 中的二进制输出,名称应该匹配 CFBundleExecutable。
.app 结构依赖于 Info.plist 文件的正确格式和包含正确信息。使用 Xcode 编辑 Info.plist,它为所有属性提供自动完成。确保:
CFBundleExecutable的值与dotnet publish生成的二进制名称相匹配 -- 通常与您的.dll程序集名称相同 不包含.dll。CFBundleName设置为您的应用程序的显示名称。如果超过15个字符,请同时设置CFBundleDisplayName。CFBundleIconFile设置为您的icns图标文件的名称(包括扩展名)。CFBundleIdentifier设置为唯一标识符,通常使用反向DNS格式 -- 例如com.myapp.macos。NSHighResolutionCapable设置为 true(在Info.plist中是<true/>)。CFBundleVersion设置为捆绑包的版本,例如 1.4.2。CFBundleShortVersionString设置为应用程序版本的用户可见字符串,例如Major.Minor.Patch。
如果需要协议注册或文件关联,请打开 Applications 文件夹中其他应用程序的 plist 文件并查看它们的字段。
示例协议:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>AppName</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLSchemes</key>
<array>
<string>i8-AppName</string>
</array>
</dict>
</array>
示例文件关联:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Sketch</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>sketch</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>icon.icns</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Default</string>
</dict>
</array>
有关可能的 Info.plist 键的更多文档,请参见此处。
如果在任何时候工具给出错误,表示您的资产文件没有 osx-64 的目标,那么请在 .csproj 的顶层 <PropertyGroup> 中添加以下运行时标识符:
<RuntimeIdentifiers>osx-x64</RuntimeIdentifiers>
根据需要添加其他运行时标识符。每个标识符应以分号(;)分隔。