I’m in the process of porting my game to macOS. I’m cross compiling from a DesktopGL application built in .NET Framework 4.7.2 with the mono-5.18.0-osx-10.9-x64
runtime via mkbundle
. On Windows and Linux everything is okay, but on macOS it has an incorrect working directory only when double-clicking to run the executable. If I run it via the terminal, it’s fine. The incorrect working directory causes it to crash since it’s looking in the wrong place to load SDL or any other native libraries/files.
I’ve tried about everything:
-
System.IO.Directory.GetCurrentDirectory()
- home folder -
System.AppContext.BaseDirectory
- home folder -
System.Diagnostics.Process.GetCurrentProcess().StartInfo.WorkingDirectory
- empty string -
System.IO.Path.GetDirectoryName(typeof(CrashHandler).Assembly.Location
- empty string -
AppDomain.CurrentDomain.DynamicDirectory
- empty string -
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
- home folder
The actual executable is in ~/Desktop/Folder, but everything either points to the home folder or is an empty string for some reason beyond me. For reference, I’m calling all of these in Main()
in Program.cs (nowhere else would work due to the crash). Any ideas on fixing this issue?