From 37cb13905f1667664bf6cd84b29fa4f72c286f6d Mon Sep 17 00:00:00 2001 From: dazinator Date: Wed, 25 Oct 2017 01:09:52 +0100 Subject: [PATCH 1/2] Fix for locating lib folder on netcore --- LibGit2Sharp/GlobalSettings.cs | 27 +++++++++++++++++---------- LibGit2Sharp/LibGit2Sharp.csproj | 3 ++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs index eef92c07c..4dfdb7958 100644 --- a/LibGit2Sharp/GlobalSettings.cs +++ b/LibGit2Sharp/GlobalSettings.cs @@ -23,19 +23,30 @@ static GlobalSettings() { if (Platform.OperatingSystem == OperatingSystemType.Windows) { + + string managedPath = string.Empty; + #if DESKTOP + var assembly = Assembly.GetExecutingAssembly(); + managedPath = assembly.CodeBase; + if (managedPath == null) + { + managedPath = assembly.Location; + } +#else + var assembly = typeof(GlobalSettings).GetTypeInfo().Assembly; + managedPath = (string)assembly.GetType().GetProperty("Location").GetValue(assembly); +#endif + + /* Assembly.CodeBase is not actually a correctly formatted * URI. It's merely prefixed with `file:///` and has its * 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; - if (managedPath == null) - { - managedPath = Assembly.GetExecutingAssembly().Location; - } - else if (managedPath.StartsWith("file:///")) + + if (managedPath.StartsWith("file:///")) { managedPath = managedPath.Substring(8).Replace('/', '\\'); } @@ -45,10 +56,6 @@ static GlobalSettings() } managedPath = Path.GetDirectoryName(managedPath); -#else - string managedPath = AppContext.BaseDirectory; -#endif - nativeLibraryPath = Path.Combine(managedPath, "lib", "win32"); } diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index cf3d667c6..d77a8c77c 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -41,7 +41,8 @@ - + + From 016fa3e3a6608b024a792b7ead20bb1d0f41eebd Mon Sep 17 00:00:00 2001 From: dazinator Date: Fri, 27 Oct 2017 23:10:45 +0100 Subject: [PATCH 2/2] Change to Native assembly search path on windows. Always use Assembly.CodeBase and then Assembly.Location for native search path. --- LibGit2Sharp.sln | 14 +++++++------- LibGit2Sharp/GlobalSettings.cs | 14 +++++++++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/LibGit2Sharp.sln b/LibGit2Sharp.sln index 64945776b..aaba7526e 100644 --- a/LibGit2Sharp.sln +++ b/LibGit2Sharp.sln @@ -1,13 +1,12 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26407.1 +VisualStudioVersion = 15.0.27004.2005 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibGit2Sharp", "LibGit2Sharp\LibGit2Sharp.csproj", "{EE6ED99F-CB12-4683-B055-D28FC7357A34}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibGit2Sharp", "LibGit2Sharp\LibGit2Sharp.csproj", "{EE6ED99F-CB12-4683-B055-D28FC7357A34}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibGit2Sharp.Tests", "LibGit2Sharp.Tests\LibGit2Sharp.Tests.csproj", "{286E63EB-04DD-4ADE-88D6-041B57800761}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibGit2Sharp.Tests", "LibGit2Sharp.Tests\LibGit2Sharp.Tests.csproj", "{286E63EB-04DD-4ADE-88D6-041B57800761}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeGenerationAttributes", "CodeGenerationAttributes\CodeGenerationAttributes.csproj", "{E1A8B99F-B2F6-4A38-9DF6-8792056D70FF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeGenerationAttributes", "CodeGenerationAttributes\CodeGenerationAttributes.csproj", "{E1A8B99F-B2F6-4A38-9DF6-8792056D70FF}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0CA739FD-DA4D-4F64-9834-DA14A3ECD04B}" ProjectSection(SolutionItems) = preProject @@ -17,8 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProjectSection EndProject Global - GlobalSection(SharedMSBuildProjectFiles) = preSolution - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -40,4 +37,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1F70B2E1-2633-4E6A-A6EE-EE0ED0288886} + EndGlobalSection EndGlobal diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs index 4dfdb7958..1bd84cc29 100644 --- a/LibGit2Sharp/GlobalSettings.cs +++ b/LibGit2Sharp/GlobalSettings.cs @@ -35,7 +35,19 @@ static GlobalSettings() } #else var assembly = typeof(GlobalSettings).GetTypeInfo().Assembly; - managedPath = (string)assembly.GetType().GetProperty("Location").GetValue(assembly); + var codeBaseProp = assembly.GetType().GetProperty("CodeBase"); + if(codeBaseProp != null) + { + managedPath = (string)codeBaseProp.GetValue(assembly); + } + if (managedPath == null) + { + var locationProp = assembly.GetType().GetProperty("Location"); + if(locationProp != null) + { + managedPath = (string)locationProp.GetValue(assembly); + } + } #endif