Skip to content

Commit 5c8a25d

Browse files
committed
Add More MacOS Docs
1 parent 1d2628b commit 5c8a25d

File tree

1 file changed

+59
-12
lines changed

1 file changed

+59
-12
lines changed

articles/getting_started/packaging_games.md

+59-12
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,6 @@ If you are targeting WindowsDX, note that players will need [the DirectX June 20
2121

2222
### [macOS](#tab/macos)
2323

24-
From the .NET CLI:
25-
26-
```cli
27-
dotnet publish -c Release -r osx-x64 -p:PublishReadyToRun=false -p:TieredCompilation=false -p:PublishAot=true --self-contained
28-
dotnet publish -c Release -r osx-arm64 -p:PublishReadyToRun=false -p:TieredCompilation=false -p:PublishAot=true --self-contained
29-
```
30-
31-
```cli
32-
lipo -create bin/Release/osx-arm64/YouGame bin/Release/osx-x64/YouGame --output bin/Release/YourGame.app/Contents/MacOS/YouGame
33-
```
34-
3524
We recommend that you distribute your game as an [application bundle](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html). Application bundles are directories with the following file structure:
3625

3726
```text
@@ -45,6 +34,38 @@ YourGame.app                    (this is your root folder)
4534
     - Info.plist            (the metadata of your app, see bellow for contents)
4635
```
4736

37+
So first lets create our directory structure.
38+
39+
```
40+
mkdir -p bin/Release/YourGame.app/Contents/MacOS/
41+
mkdir -p bin/Release/YourGame.app/Contents/Resources/Content
42+
```
43+
44+
Next we need to publish our application for both `arm64` (M1/M2 devices) and `x64` (Intel). From the .NET CLI:
45+
46+
```cli
47+
dotnet publish -c Release -r osx-x64 -p:PublishReadyToRun=false -p:TieredCompilation=false -p:PublishAot=true --self-contained
48+
dotnet publish -c Release -r osx-arm64 -p:PublishReadyToRun=false -p:TieredCompilation=false -p:PublishAot=true --self-contained
49+
```
50+
51+
Note we are making use of the `PublishAot` option. Using `Aot` has some restrictions which may require changes to your game code.
52+
Especially if you are using Reflection.
53+
54+
Next we need to comibne the two binaries into one Universal Binary which will work on both arm64 and x64 machines.
55+
We can do this using the `xcode` utility `lipo`.
56+
57+
```cli
58+
lipo -create bin/Release/net8.0/osx-arm64/publish/YourGame bin/Release/net8.0/osx-x64/publish/YourGame -output bin/Release/YourGame.app/Contents/MacOS/YourGame
59+
```
60+
61+
The above command will combine the two output executables into one.
62+
63+
Copy over your content
64+
65+
```
66+
cp -R bin/Release/net8.0/Content bin/Release/YourGame.app/Contents/Resources/Content
67+
```
68+
4869
The `Info.plist` file is a standard macOS file containing metadata about your game. Here is an example file with required and recommended values set:
4970

5071
```xml
@@ -93,6 +114,24 @@ The `Info.plist` file is a standard macOS file containing metadata about your ga
93114
For more information about Info.plist files, see the [documentation](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Introduction/Introduction.html).
94115

95116
After completing these steps, your .app folder should appear as an executable application on macOS.
117+
However it does need an icon. So we need to create an `.icns` file. We can use online tools to do this or you can use the following
118+
119+
```cli
120+
mkdir -p bin/Release/YourGame.iconset
121+
sips -z 16 16 Icon.png --out bin/Release/YourGame.iconset/icon_16x16.png
122+
sips -z 32 32 Icon.png --out bin/Release/YourGame.iconset/[email protected]
123+
sips -z 32 32 Icon.png --out bin/Release/YourGame.iconset/icon_32x32.png
124+
sips -z 64 64 Icon.png --out bin/Release/YourGame.iconset/[email protected]
125+
sips -z 128 128 Icon.png --out bin/Release/YourGame.iconset/icon_128x128.png
126+
sips -z 256 256 Icon.png --out bin/Release/YourGame.iconset/[email protected]
127+
sips -z 256 256 Icon.png --out bin/Release/YourGame.iconset/icon_256x256.png
128+
sips -z 512 512 Icon.png --out bin/Release/YourGame.iconset/[email protected]
129+
sips -z 512 512 Icon.png --out bin/Release/YourGame.iconset/icon_512x512.png
130+
sips -z 1024 1024 Icon.png bin/Release/YourGame.iconset/[email protected]
131+
iconutil -c icns bin/Release/YourGame.iconset --output bin/Release/YourGame.app/Contents/Resources/YourGame.icns
132+
```
133+
134+
Note this code is expecting an `Icon.png` file to be in the same directory. This file should be `1024` x `1024` pixels.
96135

97136
For archiving, we recommend using the .tar.gz format to preserve the execution permissions (you will likely run into permission issues if you use .zip at any point).
98137

@@ -125,9 +164,17 @@ However you do need to currently add some additional settings to your .csproj.
125164
```
126165

127166
The `TrimmerRootAssembly` stops the trimmer removing code from these assemblies. This will on the whole allow the game to run without
128-
any issues. However if you are using any Third Party assemblies, you might need to add them to this list.
167+
any issues. However if you are using any Third Party or additional assemblies, you might need to add them to this list.
129168
For MacOS it is recommended that you publish using AOT as it simplifies the app bundle.
130169

170+
See [Trim self-contained deployments and executables](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained) for more information.
171+
172+
There are some known area's yoo need to watchout for.
173+
174+
1. Using `XmlSerializer` in your game will probably cause issues. Since it uses reflection it will be difficult for the Trimmer to figure out what needs to be kept.
175+
It is recommended that instead of using the `Deserialize` method, you write your own custom deserializer using `XDocument` or `XmlReader`.
176+
Alternatively you can use the Content Pipeline and create a custom `Processor` and `Reader` to convert the Xml into a binary format that can be loaded via the usual `Content.Load<T>` method.
177+
131178
### ReadyToRun (R2R)
132179

133180
[ReadyToRun](https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0#readytorun-images) is advertised as improving application startup time, but slightly increasing binary size. We recommend not using it for games, because it produces micro stutters when your game is running.

0 commit comments

Comments
 (0)