From 7a031be7695aa991daa4696930f0ebf6bb46ecb4 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Thu, 15 Jun 2023 11:41:56 +0200 Subject: [PATCH] C#: Avoid GodotSharp as project assembly name The name GodotSharp conflicts with the name of the Godot assembly, this causes a cyclic dependency. --- modules/mono/utils/path_utils.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/mono/utils/path_utils.cpp b/modules/mono/utils/path_utils.cpp index 7b3f2127343f..a720c81faf8e 100644 --- a/modules/mono/utils/path_utils.cpp +++ b/modules/mono/utils/path_utils.cpp @@ -232,10 +232,12 @@ String relative_to(const String &p_path, const String &p_relative_to) { return relative_to_impl(path_abs_norm, relative_to_abs_norm); } +const Vector reserved_assembly_names = { "GodotSharp", "GodotSharpEditor", "Godot.SourceGenerators" }; + String get_csharp_project_name() { - String name = ProjectSettings::get_singleton()->get_setting_with_override("dotnet/project/assembly_name"); + String name = GLOBAL_GET("dotnet/project/assembly_name"); if (name.is_empty()) { - name = ProjectSettings::get_singleton()->get_setting_with_override("application/config/name"); + name = GLOBAL_GET("application/config/name"); Vector invalid_chars = Vector({ // // Windows reserved filename chars. ":", "*", "?", "\"", "<", ">", "|", @@ -248,9 +250,16 @@ String get_csharp_project_name() { name = name.replace(invalid_chars[i], "-"); } } + if (name.is_empty()) { name = "UnnamedProject"; } + + // Avoid reserved names that conflict with Godot assemblies. + if (reserved_assembly_names.has(name)) { + name += "_"; + } + return name; }