You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
To ensure Android exports are compatible with the new Play Store requirement that all `.so` libraries included are aligned to 16k, we now require C# projects to target `net9.0` which uses the correct alignment (as opposed to the current one of 4k). The thirdparty jar library has also been updated to the one from the 9.0.4 runtime package so it's compatible with non-gradle builds targeting `net9.0`. Non-android projects are not affect, the minimum TFM is still `net8.0`.
60 lines
2.0 KiB
C#
60 lines
2.0 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Text;
|
|
using Microsoft.Build.Construction;
|
|
using Microsoft.Build.Evaluation;
|
|
using GodotTools.Shared;
|
|
|
|
namespace GodotTools.ProjectEditor
|
|
{
|
|
public static class ProjectGenerator
|
|
{
|
|
public static string GodotSdkAttrValue => $"Godot.NET.Sdk/{GeneratedGodotNupkgsVersions.GodotNETSdk}";
|
|
|
|
public static string GodotMinimumRequiredTfm => "net8.0";
|
|
|
|
public static ProjectRootElement GenGameProject(string name)
|
|
{
|
|
if (name.Length == 0)
|
|
throw new ArgumentException("Project name is empty.", nameof(name));
|
|
|
|
var root = ProjectRootElement.Create(NewProjectFileOptions.None);
|
|
|
|
root.Sdk = GodotSdkAttrValue;
|
|
|
|
var mainGroup = root.AddPropertyGroup();
|
|
mainGroup.AddProperty("TargetFramework", GodotMinimumRequiredTfm);
|
|
|
|
// Non-gradle builds require .NET 9 to match the jar libraries included in the export template.
|
|
var net9 = mainGroup.AddProperty("TargetFramework", "net9.0");
|
|
net9.Condition = " '$(GodotTargetPlatform)' == 'android' ";
|
|
|
|
mainGroup.AddProperty("EnableDynamicLoading", "true");
|
|
|
|
string sanitizedName = IdentifierUtils.SanitizeQualifiedIdentifier(name, allowEmptyIdentifiers: true);
|
|
|
|
// If the name is not a valid namespace, manually set RootNamespace to a sanitized one.
|
|
if (sanitizedName != name)
|
|
mainGroup.AddProperty("RootNamespace", sanitizedName);
|
|
|
|
return root;
|
|
}
|
|
|
|
public static string GenAndSaveGameProject(string dir, string name)
|
|
{
|
|
if (name.Length == 0)
|
|
throw new ArgumentException("Project name is empty.", nameof(name));
|
|
|
|
string path = Path.Combine(dir, name + ".csproj");
|
|
|
|
var root = GenGameProject(name);
|
|
|
|
// Save (without BOM)
|
|
root.Save(path, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
|
|
|
|
return Guid.NewGuid().ToString().ToUpperInvariant();
|
|
}
|
|
}
|
|
}
|