8000 [WIP] Resolve native library location from runtimes folder by bording · Pull Request #1571 · libgit2/libgit2sharp · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Resolve native library location from runtimes folder #1571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update GetExecutingAssemblyDirectory to handle non-Windows paths
  • Loading branch information
bording committed Apr 24, 2018
commit 2619fbf5da3d27bab6a6d07812e7dd70f0b8b5c0
25 changes: 15 additions & 10 deletions LibGit2Sharp/NativeLibraryPathResolver.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Microsoft.DotNet.PlatformAbstractions;
using System.Runtime.InteropServices;
using SimpleJson;

using static Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;

namespace LibGit2Sharp
{
static partial class NativeLibraryPathResolver
{
public static string GetNativeLibraryDefaultPath()
{
var runtimeIdentifier = RuntimeEnvironment.GetRuntimeIdentifier();
var runtimeIdentifier = GetRuntimeIdentifier();
var graph = BuildRuntimeGraph();

var compatibleRuntimeIdentifiers = graph.GetCompatibleRuntimeIdentifiers(runtimeIdentifier);
Expand Down Expand Up @@ -71,19 +73,22 @@ private static string GetExecutingAssemblyDirectory()
// backslashes flipped. This is superior to EscapedCodeBase,
// which does not correctly escape things, and ambiguates a
// space (%20) with a literal `%20` in the path. Sigh.
var managedPath = Assembly.GetExecutingAssembly().CodeBase;
var managedPath = Assembly.GetExecutingAssembly().CodeBase ?? Assembly.GetExecutingAssembly().Location;

if (managedPath == null)
{
managedPath = Assembly.GetExecutingAssembly().Location;
}
else if (managedPath.StartsWith("file:///"))
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
managedPath = managedPath.Substring(8).Replace('/', '\\');
if (managedPath.StartsWith("file:///"))
< 63A4 /td> {
managedPath = managedPath.Substring(8).Replace('/', '\\');
}
else if (managedPath.StartsWith("file://"))
{
managedPath = @"\\" + managedPath.Substring(7).Replace('/', '\\');
}
}
else if (managedPath.StartsWith("file://"))
{
managedPath = @"\\" + managedPath.Substring(7).Replace('/', '\\');
managedPath = managedPath.Substring(7);
}

managedPath = Path.GetDirectoryName(managedPath);
Expand Down
0