godotengine / godotengine/godot
When building projects, Godot doesnt consistently use the same dotnet executable from c++ and the c#, specifically on mac
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Looks to be reproducible back to 4.0 based on the commits. I repro'ed it in 4.3
### System information
Godot v4.3.stable.mono - macOS 14.5.0 - Vulkan (Mobile) - integrated Apple M2 Max - Apple M2 Max (12 Threads)
### Issue description
Dotnet isn't generally required to be in a specific location, it has various mechanism to allow other projects/executables to find it, through environment variables, text file redirects and other methods. See https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#dotnet_root-dotnet_rootx86-dotnet_root_x86-dotnet_root_x64
But Godot has 2 different methods of looking up the dotnet executable, in c# and from the c++ and they don't match.
C# is only looking for the executable in 2 locations:
["/usr/local/share/dotnet/dotnet";](https://github.com/godotengine/godot/blob/master/modules/mono/editor/GodotTools/GodotTools/Build/DotNetFinder.cs#L29)
and
["/usr/local/share/dotnet/x64/dotnet"](https://github.com/godotengine/godot/blob/master/modules/mono/editor/GodotTools/GodotTools/Build/DotNetFinder.cs#L23)
The c++ is correctly using the common c# environment variables to find the right version, first checking environment variables like DOTNET_ROOT_ARM64 and then DOTNET_ROOT (it could maybe be slightly better by searching the path):
https://github.com/godotengine/godot/blob/master/modules/mono/editor/hostfxr_resolver.cpp#L335
In my tests, I was hoping that [DOTNET_HOST_PATH](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#dotnet_host_path) would have been set by the pipeline out of the box, but its not at that code location in DotNetFinder.cs.
I think the solution would end up looking maybe like this (but maybe there is a real library function we could be calling):
https://github.com/dotnet/roslyn/blob/main/src/Compilers/Shared/RuntimeHostInfo.cs#L59
### Steps to reproduce
On mac, install dotnet or the sdks into a non-standard location (like say maybe you might do on a build machine).
Then set DOTNET_ROOT to point at that location as the dotnet documentation suggests: https://learn.microsoft.com/en-us/dotnet/core/install/macos#set-environment-variables-system-wide
Then build for Android and the c# will not be able to find the right dotnet executable.
### Minimal reproduction project (MRP)
Since the bug comes from the dotnet installation location variations, not the project, any project will show the problem.
Contributor guide
Research direction
Start with modules/mono/editor/GodotTools/GodotTools/Build/DotNetFinder.cs and modules/mono/editor/hostfxr_resolver.cpp, comparing how C# and C++ locate dotnet on macOS. Reproduce with a non-standard SDK location and DOTNET_ROOT set, then verify that Android builds use the same discovered executable in both paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100