mirror of
https://github.com/godotengine/godot
synced 2024-09-15 22:10:09 +00:00
Merge pull request #72554 from RedworkDE/net-appcontext-basedirectory
C#: Set AppContext.BaseDirectory for editor builds
This commit is contained in:
commit
1ff2204cfe
|
@ -21,6 +21,26 @@ namespace GodotPlugins
|
||||||
_resolver = new AssemblyDependencyResolver(pluginPath);
|
_resolver = new AssemblyDependencyResolver(pluginPath);
|
||||||
_sharedAssemblies = sharedAssemblies;
|
_sharedAssemblies = sharedAssemblies;
|
||||||
_mainLoadContext = mainLoadContext;
|
_mainLoadContext = mainLoadContext;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(AppContext.BaseDirectory))
|
||||||
|
{
|
||||||
|
// See https://github.com/dotnet/runtime/blob/v6.0.0/src/libraries/System.Private.CoreLib/src/System/AppContext.AnyOS.cs#L17-L35
|
||||||
|
// but Assembly.Location is unavailable, because we load assemblies from memory.
|
||||||
|
string? baseDirectory = Path.GetDirectoryName(pluginPath);
|
||||||
|
if (baseDirectory != null)
|
||||||
|
{
|
||||||
|
if (!Path.EndsInDirectorySeparator(baseDirectory))
|
||||||
|
baseDirectory += Path.PathSeparator;
|
||||||
|
// This SetData call effectively sets AppContext.BaseDirectory
|
||||||
|
// See https://github.com/dotnet/runtime/blob/v6.0.0/src/libraries/System.Private.CoreLib/src/System/AppContext.cs#L21-L25
|
||||||
|
AppDomain.CurrentDomain.SetData("APP_CONTEXT_BASE_DIRECTORY", baseDirectory);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO: How to log from GodotPlugins? (delegate pointer?)
|
||||||
|
Console.Error.WriteLine("Failed to set AppContext.BaseDirectory. Dynamic loading of libraries may fail.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Assembly? Load(AssemblyName assemblyName)
|
protected override Assembly? Load(AssemblyName assemblyName)
|
||||||
|
|
Loading…
Reference in a new issue