C#: Use custom project setting for C# project files name
The setting is initially assigned the name of the Godot project, but it's kept freezed to prevent issues when renaming the Godot project. The user can always rename the C# project and solution manually and change the setting to the new name. Co-authored-by: Ignacio Roldán Etcheverry <ignalfonsore@gmail.com>
This commit is contained in:
parent
7637b5d925
commit
31d09a807e
9 changed files with 65 additions and 31 deletions
|
@ -722,19 +722,24 @@ bool CSharpLanguage::is_assembly_reloading_needed() {
|
||||||
GDMonoAssembly *proj_assembly = gdmono->get_project_assembly();
|
GDMonoAssembly *proj_assembly = gdmono->get_project_assembly();
|
||||||
|
|
||||||
String appname = ProjectSettings::get_singleton()->get("application/config/name");
|
String appname = ProjectSettings::get_singleton()->get("application/config/name");
|
||||||
String appname_safe = OS::get_singleton()->get_safe_dir_name(appname);
|
String assembly_name = ProjectSettings::get_singleton()->get_setting("mono/project/assembly_name");
|
||||||
if (appname_safe.empty()) {
|
|
||||||
appname_safe = "UnnamedProject";
|
if (assembly_name.empty()) {
|
||||||
|
String appname_safe = OS::get_singleton()->get_safe_dir_name(appname);
|
||||||
|
if (appname_safe.empty()) {
|
||||||
|
appname_safe = "UnnamedProject";
|
||||||
|
}
|
||||||
|
assembly_name = appname_safe;
|
||||||
}
|
}
|
||||||
|
|
||||||
appname_safe += ".dll";
|
assembly_name += ".dll";
|
||||||
|
|
||||||
if (proj_assembly) {
|
if (proj_assembly) {
|
||||||
String proj_asm_path = proj_assembly->get_path();
|
String proj_asm_path = proj_assembly->get_path();
|
||||||
|
|
||||||
if (!FileAccess::exists(proj_asm_path)) {
|
if (!FileAccess::exists(proj_asm_path)) {
|
||||||
// Maybe it wasn't loaded from the default path, so check this as well
|
// Maybe it wasn't loaded from the default path, so check this as well
|
||||||
proj_asm_path = GodotSharpDirs::get_res_temp_assemblies_dir().plus_file(appname_safe);
|
proj_asm_path = GodotSharpDirs::get_res_temp_assemblies_dir().plus_file(assembly_name);
|
||||||
if (!FileAccess::exists(proj_asm_path))
|
if (!FileAccess::exists(proj_asm_path))
|
||||||
return false; // No assembly to load
|
return false; // No assembly to load
|
||||||
}
|
}
|
||||||
|
@ -742,7 +747,7 @@ bool CSharpLanguage::is_assembly_reloading_needed() {
|
||||||
if (FileAccess::get_modified_time(proj_asm_path) <= proj_assembly->get_modified_time())
|
if (FileAccess::get_modified_time(proj_asm_path) <= proj_assembly->get_modified_time())
|
||||||
return false; // Already up to date
|
return false; // Already up to date
|
||||||
} else {
|
} else {
|
||||||
if (!FileAccess::exists(GodotSharpDirs::get_res_temp_assemblies_dir().plus_file(appname_safe)))
|
if (!FileAccess::exists(GodotSharpDirs::get_res_temp_assemblies_dir().plus_file(assembly_name)))
|
||||||
return false; // No assembly to load
|
return false; // No assembly to load
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -231,7 +231,7 @@ namespace GodotTools.Export
|
||||||
RunLipo(new[] {CompileForArch("arm64"), CompileForArch("x86_64")}, libFilePath);
|
RunLipo(new[] {CompileForArch("arm64"), CompileForArch("x86_64")}, libFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
string projectAssemblyName = GodotSharpEditor.ProjectAssemblyName;
|
string projectAssemblyName = GodotSharpDirs.ProjectAssemblyName;
|
||||||
string libAotName = $"lib-aot-{projectAssemblyName}";
|
string libAotName = $"lib-aot-{projectAssemblyName}";
|
||||||
|
|
||||||
string libAotXcFrameworkPath = Path.Combine(aotTempDir, $"{libAotName}.xcframework");
|
string libAotXcFrameworkPath = Path.Combine(aotTempDir, $"{libAotName}.xcframework");
|
||||||
|
|
|
@ -167,7 +167,7 @@ namespace GodotTools.Export
|
||||||
|
|
||||||
var assemblies = new Godot.Collections.Dictionary<string, string>();
|
var assemblies = new Godot.Collections.Dictionary<string, string>();
|
||||||
|
|
||||||
string projectDllName = GodotSharpEditor.ProjectAssemblyName;
|
string projectDllName = GodotSharpDirs.ProjectAssemblyName;
|
||||||
string projectDllSrcDir = Path.Combine(GodotSharpDirs.ResTempAssembliesBaseDir, buildConfig);
|
string projectDllSrcDir = Path.Combine(GodotSharpDirs.ResTempAssembliesBaseDir, buildConfig);
|
||||||
string projectDllSrcPath = Path.Combine(projectDllSrcDir, $"{projectDllName}.dll");
|
string projectDllSrcPath = Path.Combine(projectDllSrcDir, $"{projectDllName}.dll");
|
||||||
|
|
||||||
|
|
|
@ -39,18 +39,6 @@ namespace GodotTools
|
||||||
|
|
||||||
public bool SkipBuildBeforePlaying { get; set; } = false;
|
public bool SkipBuildBeforePlaying { get; set; } = false;
|
||||||
|
|
||||||
public static string ProjectAssemblyName
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
string projectAssemblyName = (string)ProjectSettings.GetSetting("application/config/name");
|
|
||||||
projectAssemblyName = projectAssemblyName.ToSafeDirName();
|
|
||||||
if (string.IsNullOrEmpty(projectAssemblyName))
|
|
||||||
projectAssemblyName = "UnnamedProject";
|
|
||||||
return projectAssemblyName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool CreateProjectSolution()
|
private bool CreateProjectSolution()
|
||||||
{
|
{
|
||||||
using (var pr = new EditorProgress("create_csharp_solution", "Generating solution...".TTR(), 3))
|
using (var pr = new EditorProgress("create_csharp_solution", "Generating solution...".TTR(), 3))
|
||||||
|
@ -60,7 +48,7 @@ namespace GodotTools
|
||||||
string resourceDir = ProjectSettings.GlobalizePath("res://");
|
string resourceDir = ProjectSettings.GlobalizePath("res://");
|
||||||
|
|
||||||
string path = resourceDir;
|
string path = resourceDir;
|
||||||
string name = ProjectAssemblyName;
|
string name = GodotSharpDirs.ProjectAssemblyName;
|
||||||
|
|
||||||
string guid = CsProjOperations.GenerateGameProject(path, name);
|
string guid = CsProjOperations.GenerateGameProject(path, name);
|
||||||
|
|
||||||
|
@ -375,7 +363,8 @@ namespace GodotTools
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public bool OverridesExternalEditor()
|
public bool OverridesExternalEditor()
|
||||||
{
|
{
|
||||||
return (ExternalEditorId)_editorSettings.GetSetting("mono/editor/external_editor") != ExternalEditorId.None;
|
return (ExternalEditorId)_editorSettings.GetSetting("mono/editor/external_editor") !=
|
||||||
|
ExternalEditorId.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Build()
|
public override bool Build()
|
||||||
|
@ -396,7 +385,7 @@ namespace GodotTools
|
||||||
// NOTE: The order in which changes are made to the project is important
|
// NOTE: The order in which changes are made to the project is important
|
||||||
|
|
||||||
// Migrate to MSBuild project Sdks style if using the old style
|
// Migrate to MSBuild project Sdks style if using the old style
|
||||||
ProjectUtils.MigrateToProjectSdksStyle(msbuildProject, ProjectAssemblyName);
|
ProjectUtils.MigrateToProjectSdksStyle(msbuildProject, GodotSharpDirs.ProjectAssemblyName);
|
||||||
|
|
||||||
ProjectUtils.EnsureGodotSdkIsUpToDate(msbuildProject);
|
ProjectUtils.EnsureGodotSdkIsUpToDate(msbuildProject);
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ namespace GodotTools.Internals
|
||||||
public static string MonoSolutionsDir => internal_MonoSolutionsDir();
|
public static string MonoSolutionsDir => internal_MonoSolutionsDir();
|
||||||
public static string BuildLogsDirs => internal_BuildLogsDirs();
|
public static string BuildLogsDirs => internal_BuildLogsDirs();
|
||||||
|
|
||||||
|
public static string ProjectAssemblyName => internal_ProjectAssemblyName();
|
||||||
public static string ProjectSlnPath => internal_ProjectSlnPath();
|
public static string ProjectSlnPath => internal_ProjectSlnPath();
|
||||||
public static string ProjectCsProjPath => internal_ProjectCsProjPath();
|
public static string ProjectCsProjPath => internal_ProjectCsProjPath();
|
||||||
|
|
||||||
|
@ -74,6 +75,9 @@ namespace GodotTools.Internals
|
||||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||||
private static extern string internal_BuildLogsDirs();
|
private static extern string internal_BuildLogsDirs();
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||||
|
private static extern string internal_ProjectAssemblyName();
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||||
private static extern string internal_ProjectSlnPath();
|
private static extern string internal_ProjectSlnPath();
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,14 @@ MonoString *godot_icall_GodotSharpDirs_BuildLogsDirs() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MonoString *godot_icall_GodotSharpDirs_ProjectAssemblyName() {
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
return GDMonoMarshal::mono_string_from_godot(GodotSharpDirs::get_project_assembly_name());
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
MonoString *godot_icall_GodotSharpDirs_ProjectSlnPath() {
|
MonoString *godot_icall_GodotSharpDirs_ProjectSlnPath() {
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
return GDMonoMarshal::mono_string_from_godot(GodotSharpDirs::get_project_sln_path());
|
return GDMonoMarshal::mono_string_from_godot(GodotSharpDirs::get_project_sln_path());
|
||||||
|
@ -388,6 +396,7 @@ void register_editor_internal_calls() {
|
||||||
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_MonoLogsDir", godot_icall_GodotSharpDirs_MonoLogsDir);
|
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_MonoLogsDir", godot_icall_GodotSharpDirs_MonoLogsDir);
|
||||||
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_MonoSolutionsDir", godot_icall_GodotSharpDirs_MonoSolutionsDir);
|
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_MonoSolutionsDir", godot_icall_GodotSharpDirs_MonoSolutionsDir);
|
||||||
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_BuildLogsDirs", godot_icall_GodotSharpDirs_BuildLogsDirs);
|
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_BuildLogsDirs", godot_icall_GodotSharpDirs_BuildLogsDirs);
|
||||||
|
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_ProjectAssemblyName", godot_icall_GodotSharpDirs_ProjectAssemblyName);
|
||||||
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_ProjectSlnPath", godot_icall_GodotSharpDirs_ProjectSlnPath);
|
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_ProjectSlnPath", godot_icall_GodotSharpDirs_ProjectSlnPath);
|
||||||
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_ProjectCsProjPath", godot_icall_GodotSharpDirs_ProjectCsProjPath);
|
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_ProjectCsProjPath", godot_icall_GodotSharpDirs_ProjectCsProjPath);
|
||||||
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_DataEditorToolsDir", godot_icall_GodotSharpDirs_DataEditorToolsDir);
|
GDMonoUtils::add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_DataEditorToolsDir", godot_icall_GodotSharpDirs_DataEditorToolsDir);
|
||||||
|
|
|
@ -102,6 +102,7 @@ public:
|
||||||
String mono_solutions_dir;
|
String mono_solutions_dir;
|
||||||
String build_logs_dir;
|
String build_logs_dir;
|
||||||
|
|
||||||
|
String project_assembly_name;
|
||||||
String sln_filepath;
|
String sln_filepath;
|
||||||
String csproj_filepath;
|
String csproj_filepath;
|
||||||
|
|
||||||
|
@ -144,16 +145,35 @@ private:
|
||||||
mono_solutions_dir = mono_user_dir.plus_file("solutions");
|
mono_solutions_dir = mono_user_dir.plus_file("solutions");
|
||||||
build_logs_dir = mono_user_dir.plus_file("build_logs");
|
build_logs_dir = mono_user_dir.plus_file("build_logs");
|
||||||
|
|
||||||
|
GLOBAL_DEF("mono/project/assembly_name", "");
|
||||||
|
GLOBAL_DEF("mono/project/solution_directory", "");
|
||||||
|
GLOBAL_DEF("mono/project/c#_project_directory", "");
|
||||||
|
|
||||||
String appname = ProjectSettings::get_singleton()->get("application/config/name");
|
String appname = ProjectSettings::get_singleton()->get("application/config/name");
|
||||||
String appname_safe = OS::get_singleton()->get_safe_dir_name(appname);
|
String appname_safe = OS::get_singleton()->get_safe_dir_name(appname);
|
||||||
if (appname_safe.empty()) {
|
if (appname_safe.empty()) {
|
||||||
appname_safe = "UnnamedProject";
|
appname_safe = "UnnamedProject";
|
||||||
}
|
}
|
||||||
|
|
||||||
String base_path = ProjectSettings::get_singleton()->globalize_path("res://");
|
project_assembly_name = ProjectSettings::get_singleton()->get("mono/project/assembly_name");
|
||||||
|
if (project_assembly_name.empty()) {
|
||||||
|
project_assembly_name = appname_safe;
|
||||||
|
ProjectSettings::get_singleton()->set("mono/project/assembly_name", project_assembly_name);
|
||||||
|
}
|
||||||
|
|
||||||
sln_filepath = base_path.plus_file(appname_safe + ".sln");
|
String sln_parent_dir = ProjectSettings::get_singleton()->get("mono/project/solution_directory");
|
||||||
csproj_filepath = base_path.plus_file(appname_safe + ".csproj");
|
if (sln_parent_dir.empty()) {
|
||||||
|
sln_parent_dir = "res://";
|
||||||
|
}
|
||||||
|
|
||||||
|
String csproj_parent_dir = ProjectSettings::get_singleton()->get("mono/project/c#_project_directory");
|
||||||
|
if (csproj_parent_dir.empty()) {
|
||||||
|
csproj_parent_dir = "res://";
|
||||||
|
}
|
||||||
|
|
||||||
|
sln_filepath = ProjectSettings::get_singleton()->globalize_path(sln_parent_dir).plus_file(project_assembly_name + ".sln");
|
||||||
|
|
||||||
|
csproj_filepath = ProjectSettings::get_singleton()->globalize_path(csproj_parent_dir).plus_file(project_assembly_name + ".csproj");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
String exe_dir = OS::get_singleton()->get_executable_path().get_base_dir();
|
String exe_dir = OS::get_singleton()->get_executable_path().get_base_dir();
|
||||||
|
@ -288,6 +308,10 @@ String get_build_logs_dir() {
|
||||||
return _GodotSharpDirs::get_singleton().build_logs_dir;
|
return _GodotSharpDirs::get_singleton().build_logs_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String get_project_assembly_name() {
|
||||||
|
return _GodotSharpDirs::get_singleton().project_assembly_name;
|
||||||
|
}
|
||||||
|
|
||||||
String get_project_sln_path() {
|
String get_project_sln_path() {
|
||||||
return _GodotSharpDirs::get_singleton().sln_filepath;
|
return _GodotSharpDirs::get_singleton().sln_filepath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ String get_mono_logs_dir();
|
||||||
String get_mono_solutions_dir();
|
String get_mono_solutions_dir();
|
||||||
String get_build_logs_dir();
|
String get_build_logs_dir();
|
||||||
|
|
||||||
|
String get_project_assembly_name();
|
||||||
String get_project_sln_path();
|
String get_project_sln_path();
|
||||||
String get_project_csproj_path();
|
String get_project_csproj_path();
|
||||||
|
|
||||||
|
|
|
@ -987,13 +987,15 @@ bool GDMono::_load_project_assembly() {
|
||||||
if (project_assembly)
|
if (project_assembly)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
String appname = ProjectSettings::get_singleton()->get("application/config/name");
|
String assembly_name = ProjectSettings::get_singleton()->get("mono/project/assembly_name");
|
||||||
String appname_safe = OS::get_singleton()->get_safe_dir_name(appname);
|
|
||||||
if (appname_safe.empty()) {
|
if (assembly_name.empty()) {
|
||||||
appname_safe = "UnnamedProject";
|
String appname = ProjectSettings::get_singleton()->get("application/config/name");
|
||||||
|
String appname_safe = OS::get_singleton()->get_safe_dir_name(appname);
|
||||||
|
assembly_name = appname_safe;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = load_assembly(appname_safe, &project_assembly);
|
bool success = load_assembly(assembly_name, &project_assembly);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
mono_assembly_set_main(project_assembly->get_assembly());
|
mono_assembly_set_main(project_assembly->get_assembly());
|
||||||
|
|
Loading…
Reference in a new issue