Compilación con .NET
Requerimientos
-
Puedes utilizar
dotnet --infopara comprobar qué versiones del SDK .NET están instaladas.
Habilitar el módulo .NET
Nota
El soporte de C# para Godot ha utilizado históricamente el runtime de Mono en lugar del .NET Runtime e internamente muchas cosas todavía se llaman mono en lugar de dotnet o se las referencia de otra manera como mono.
By default, the .NET module is disabled when building. To enable it, add the
option module_mono_enabled=yes to the SCons command line, while otherwise
following the instructions for building the desired Godot binaries.
Generar el pegamento
Parts of the sources of the managed libraries are generated from the ClassDB.
These source files must be generated before building the managed libraries.
They can be generated by any .NET-enabled Godot editor binary by running it with
the parameters --headless --generate-mono-glue followed by the path to an
output directory.
This path must be modules/mono/glue in the Godot directory:
<godot_binary> --headless --generate-mono-glue modules/mono/glue
This command will tell Godot to generate the C# bindings for the Godot API at
modules/mono/glue/GodotSharp/GodotSharp/Generated, and the C# bindings for
the editor tools at modules/mono/glue/GodotSharp/GodotSharpEditor/Generated.
Once these files are generated, you can build Godot's managed libraries for all
the desired targets without having to repeat this process.
<godot_binary> refers to the editor binary you compiled with the .NET module
enabled. Its exact name will differ based on your system and configuration, but
should be of the form bin/godot.<platform>.editor.<arch>.mono, e.g.
bin/godot.linuxbsd.editor.x86_64.mono or
bin/godot.windows.editor.x86_32.mono.exe. Be especially aware of the
.mono suffix! If you've previously compiled Godot without .NET support, you
might have similarly named binaries without this suffix. These binaries can't be
used to generate the .NET glue.
Nota
Las fuentes de glue deben regenerarse cada vez que cambie la API registrada en ClassDB. Es decir, por ejemplo, cuando se registra un nuevo método en la API de scripting o cuando uno de los parámetros de dicho método cambia. Godot mostrará un error al iniciarse si hay una discrepancia de API entre ClassDB y las fuentes de glue.
Building the managed libraries
Once you have generated the .NET glue, you can build the managed libraries with
the build_assemblies.py script:
./modules/mono/build_scripts/build_assemblies.py --godot-output-dir=./bin
Si todo salió bien, la carpeta GodotSharp conteniendo las bibliotecas, debería estar en el directorio bin.
Nota
Por defecto, todas las compilaciones de desarrollo comparten un número de versión, lo que puede causar algunos problemas con el almacenamiento en caché de los paquetes NuGet. Para resolver este problema, use GODOT_VERSION_STATUS para darle a cada compilación una versión única o elimine GodotNuGetFallbackFolder después de cada compilación para borrar la memoria caché de paquetes.
Unlike "classical" Godot builds, when building with the .NET module enabled (and depending on the target platform), a data directory may be created both for the editor and for exported projects. This directory is important for proper functioning and must be distributed together with Godot. More details about this directory in Data directory.
Build Platform
Proporcione el argumento --godot-platform=<platform> para controlar para qué plataforma específica se crearán las bibliotecas. Omita este argumento para crear las bibliotecas para el sistema actual.
Actualmente, esto solo controla la inclusión del soporte para Visual Studio como editor externo, las bibliotecas son idénticas por lo demás.
Uso de los paquetes NuGet
Los conjuntos de API, los generadores de código fuente y el SDK de proyectos MSBuild personalizados se distribuyen como paquetes NuGet. Todo esto es transparente para el usuario, pero puede complicar las cosas durante el desarrollo.
Para utilizar Godot con una versión de desarrollo de esos paquetes, se debe crear una fuente NuGet local donde MSBuild pueda encontrarlos.
En primer lugar, elige una ubicación para la fuente NuGet local. Si no tiene ninguna preferencia, crea un directorio vacío en una de estas ubicaciones recomendadas:
En Windows,
C:\Users\<nombre de usuario>\MyLocalNugetSourceEn Linux, *BSD, etc.,
~/MyLocalNugetSource
Esta ruta se referenciará más adelante <my_local_source>.
Después de seleccionar un directorio, ejecute este comando CLI de .NET para configurar NuGet para que use su fuente local:
dotnet nuget add source <my_local_source> --name MyLocalNugetSource
Cuando ejecute el script build_assemblies.py, pase <my_local_source> a la opción --push-nupkgs-local:
./modules/mono/build_scripts/build_assemblies.py --godot-output-dir ./bin --push-nupkgs-local <my_local_source>
Esta opción garantiza que los paquetes se agregarán a la fuente NuGet local especificada y que las versiones conflictivas del paquete se eliminarán de su memoria caché. Se recomienda utilizar siempre esta opción al crear soluciones C# durante el desarrollo para evitar errores.
Building without depending on deprecated features (NO_DEPRECATED)
When building Godot without deprecated classes and functions, i.e. the deprecated=no
argument for scons, the managed libraries must also be built without dependencies to deprecated code.
This is done by passing the --no-deprecated argument:
./modules/mono/build_scripts/build_assemblies.py --godot-output-dir ./bin --push-nupkgs-local <my_local_source> --no-deprecated
Soporte para Doble Precisión (REAL_T_IS_DOUBLE)
Al construir Godot con soporte para doble precisión, es decir, el argumento precision=double para SCons, las bibliotecas administradas deben ajustarse para que coincidan pasando el argumento --precision=double:
./modules/mono/build_scripts/build_assemblies.py --godot-output-dir ./bin --push-nupkgs-local <my_local_source> --precision=double
Ejemplos
Ejemplo (Windows)
# Build editor binary
scons platform=windows target=editor module_mono_enabled=yes
# Build export templates
scons platform=windows target=template_debug module_mono_enabled=yes
scons platform=windows target=template_release module_mono_enabled=yes
# Generate glue sources
bin/godot.windows.editor.x86_64.mono --headless --generate-mono-glue modules/mono/glue
# Build .NET assemblies
./modules/mono/build_scripts/build_assemblies.py --godot-output-dir ./bin --push-nupkgs-local <my_local_source> --godot-platform=windows
Ejemplo (Linux, *BSD)
# Build editor binary
scons platform=linuxbsd target=editor module_mono_enabled=yes
# Build export templates
scons platform=linuxbsd target=template_debug module_mono_enabled=yes
scons platform=linuxbsd target=template_release module_mono_enabled=yes
# Generate glue sources
bin/godot.linuxbsd.editor.x86_64.mono --headless --generate-mono-glue modules/mono/glue
# Generate binaries
./modules/mono/build_scripts/build_assemblies.py --godot-output-dir ./bin --push-nupkgs-local <my_local_source> --godot-platform=linuxbsd
Directorio de Datos
The data directory is a dependency for Godot binaries built with the .NET module enabled. It contains important files for the correct functioning of Godot. It must be distributed together with the Godot executable.
Editor
El nombre del directorio de datos del editor Godot siempre será GodotSharp. Este directorio contiene un subdirectorio Api con los ensambles de la API de Godot y un subdirectorio Tools con las herramientas que requiere el editor, como los ensambles GodotTools y sus dependencias.
En macOS, si el editor Godot se distribuye como un paquete, el directorio GodotSharp puede ubicarse en el directorio <bundle_name>.app/Contents/Resources/ dentro del paquete.
Plantillas de exportación
The data directory for exported projects is generated by the editor during the
export. It is named data_<APPNAME>_<ARCH>, where <APPNAME> is the
application name as specified in the project setting application/config/name
and <ARCH> is the current architecture of the export.
En el caso de exportaciones de múltiples arquitecturas, se generarán múltiples directorios de datos de este tipo.
Opciones de la línea de comandos
The following is the list of command-line options available when building with the .NET module:
module_mono_enabled=yes | no
Build Godot with the .NET module enabled.