Skip to content

Commit 44c5979

Browse files
committed
Fix native module loading
1 parent cbe3622 commit 44c5979

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/Nerdbank.GitVersioning.Tasks/GitLoaderContext.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ internal class GitLoaderContext : AssemblyLoadContext
1717

1818
protected override Assembly Load(AssemblyName assemblyName)
1919
{
20-
if (assemblyName.Name == "LibGit2Sharp")
21-
{
22-
var path = Path.Combine(Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location), assemblyName.Name + ".dll");
23-
return LoadFromAssemblyPath(path);
24-
}
25-
26-
return Default.LoadFromAssemblyName(assemblyName);
20+
var path = Path.Combine(Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location), assemblyName.Name + ".dll");
21+
return File.Exists(path)
22+
? LoadFromAssemblyPath(path)
23+
: Default.LoadFromAssemblyName(assemblyName);
2724
}
2825

2926
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
@@ -56,7 +53,7 @@ protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
5653
internal static string GetNativeLibraryDirectory()
5754
{
5855
var dir = Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location);
59-
return Path.Combine(dir, "runtimes", RuntimeIdMap.GetNativeLibraryDirectoryName(RuntimeEnvironment.GetRuntimeIdentifier()), "native");
56+
return Path.Combine(dir, "..", "runtimes", RuntimeIdMap.GetNativeLibraryDirectoryName(RuntimeEnvironment.GetRuntimeIdentifier()), "native");
6057
}
6158

6259
private static string GetNativeLibraryExtension()

src/Nerdbank.GitVersioning.Tasks/Nerdbank.GitVersioning.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<file src="$BaseOutputPath$net461\Nerdbank.GitVersioning.Tasks.dll" target="build\MSBuildFull\Nerdbank.GitVersioning.Tasks.dll" />
2222
<file src="$BaseOutputPath$net461\Newtonsoft.Json.dll" target="build\MSBuildFull\Newtonsoft.Json.dll" />
2323
<file src="$BaseOutputPath$net461\Validation.dll" target="build\MSBuildFull\Validation.dll" />
24-
<file src="$LibGit2SharpNativeBinaries$runtimes\**" target="build\lib\" />
24+
<file src="$LibGit2SharpNativeBinaries$runtimes\**" target="build\runtimes\" />
2525

2626
<!-- Additional copies to work around DllNotFoundException on Mono (https://github.com/AArnott/Nerdbank.GitVersioning/issues/222) -->
2727
<file src="$LibGit2SharpNativeBinaries$runtimes\osx\native\libgit2-a904fc6.dylib" target="build\MSBuildFull\lib\osx\libgit2-a904fc6.dylib" />

0 commit comments

Comments
 (0)