Skip to content

The information about NativeAOT needs to be added to the C# platform support section. #9239

Description

@Foxchandaisuki

Your Godot version: 4.2

Issue description: It is necessary to add the text from the Desktop paragraph and other sections of this article to the document's page to inform users that they can AOT compile C# code to native code and how to do so.

The items listed below are the exact content that needs to be included.

Before .NET unification there was the Windows-only .NET Framework and the cross-platform Mono and .NET Core. Unification means there will be just one .NET going forward, so the next release after .NET Core 3.0 was named .NET 5, and Mono and .NET Framework won’t have any new major releases.

The term Mono can be used to refer to a collection of technologies. With .NET unification, the Mono framework is deprecated, but the runtime is still supported. Unified .NET uses both the CoreCLR and the Mono runtimes, but Mono is the only runtime that supports mobile and web platforms.

However, in .NET 7.0 a new runtime became available, NativeAOT, which allows publishing native binaries built for a specific platform, instead of the JIT-based portable binaries. In .NET 7.0, NativeAOT only supports Windows and Linux, but in .NET 8.0 it adds support for macOS and experimental support for Android and iOS. This means in .NET 8.0 NativeAOT can be used as an alternative to Mono for mobile platforms.

Desktop platforms have been supported since 4.0, but what some users may not know is that those platforms support all .NET runtimes. This is not new to 4.2 and, in fact, has been supported since 4.0. Godot’s C# integration uses standard .NET so everything that works in a normal C# project should work in Godot too. To use a different runtime from the default (which is CoreCLR), users have to modify the C# project file (.csproj) as documented in the Microsoft documentation.

To enable NativeAOT in desktop platforms, make sure to target .NET 7.0 or higher and set the property to true. Also, since Godot uses reflection, make sure to root the assemblies (this is done automatically for you when exporting to iOS because NativeAOT is currently the only supported runtime). Here’s an example C# project:

<Project Sdk="Godot.NET.Sdk/4.2.0">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
    <!-- Use NativeAOT. -->
    <PublishAOT>true</PublishAOT>
  </PropertyGroup>
  <ItemGroup>
    <!-- Root the assemblies to avoid trimming. -->
    <TrimmerRootAssembly Include="GodotSharp" />
    <TrimmerRootAssembly Include="$(TargetName)" />
  </ItemGroup>
</Project>

URL to the documentation page (if already existing): https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/index.html#c-platform-support

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions