From 6f876678f5fdce789d77750dbc3f7f6101978b77 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Mon, 13 Apr 2026 00:27:11 +0800 Subject: [PATCH] editor: prefer bundled mono runtime discovery --- editor/CMakeLists.txt | 12 ++++++++---- editor/src/Scripting/EditorScriptAssemblyBuilder.cpp | 5 +++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index b66fd6b5..94618b59 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -32,11 +32,15 @@ if(NOT TARGET XCEngine) option(XCENGINE_ENABLE_MONO_SCRIPTING "Build the Mono-based C# scripting runtime" ON) if(NOT DEFINED XCENGINE_MONO_ROOT_DIR OR XCENGINE_MONO_ROOT_DIR STREQUAL "") - file(GLOB XCENGINE_MONO_ROOT_DIR_CANDIDATES "${XCENGINE_ROOT_DIR}/*/Fermion/Fermion/external/mono") - if(XCENGINE_MONO_ROOT_DIR_CANDIDATES) - list(GET XCENGINE_MONO_ROOT_DIR_CANDIDATES 0 XCENGINE_MONO_ROOT_DIR_DEFAULT) + if(EXISTS "${XCENGINE_ROOT_DIR}/engine/third_party/mono/binary/mscorlib.dll") + set(XCENGINE_MONO_ROOT_DIR_DEFAULT "${XCENGINE_ROOT_DIR}/engine/third_party/mono") else() - set(XCENGINE_MONO_ROOT_DIR_DEFAULT "${XCENGINE_ROOT_DIR}/managed/mono") + file(GLOB XCENGINE_MONO_ROOT_DIR_CANDIDATES "${XCENGINE_ROOT_DIR}/*/Fermion/Fermion/external/mono") + if(XCENGINE_MONO_ROOT_DIR_CANDIDATES) + list(GET XCENGINE_MONO_ROOT_DIR_CANDIDATES 0 XCENGINE_MONO_ROOT_DIR_DEFAULT) + else() + set(XCENGINE_MONO_ROOT_DIR_DEFAULT "${XCENGINE_ROOT_DIR}/managed/mono") + endif() endif() set( diff --git a/editor/src/Scripting/EditorScriptAssemblyBuilder.cpp b/editor/src/Scripting/EditorScriptAssemblyBuilder.cpp index 11b38d53..5ab15801 100644 --- a/editor/src/Scripting/EditorScriptAssemblyBuilder.cpp +++ b/editor/src/Scripting/EditorScriptAssemblyBuilder.cpp @@ -48,6 +48,11 @@ std::filesystem::path FindBundledMonoRootDirectory(const std::filesystem::path& return {}; } + const std::filesystem::path projectBundledMonoRoot = repositoryRoot / "engine" / "third_party" / "mono"; + if (std::filesystem::exists(projectBundledMonoRoot / "binary" / "mscorlib.dll", ec)) { + return projectBundledMonoRoot.lexically_normal(); + } + for (std::filesystem::directory_iterator it(repositoryRoot, ec), end; it != end && !ec; it.increment(ec)) { if (ec || !it->is_directory(ec)) { continue;