Skip to content

Fix for locating lib folder on netcore #1499

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
Closed
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions LibGit2Sharp.sln
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -40,4 +37,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1F70B2E1-2633-4E6A-A6EE-EE0ED0288886}
EndGlobalSection
EndGlobal
39 changes: 29 additions & 10 deletions LibGit2Sharp/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,42 @@ 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;
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


/* 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('/', '\\');
}
Expand All @@ -45,10 +68,6 @@ static GlobalSettings()
}

managedPath = Path.GetDirectoryName(managedPath);
#else
string managedPath = AppContext.BaseDirectory;
#endif

nativeLibraryPath = Path.Combine(managedPath, "lib", "win32");
}

Expand Down
3 changes: 2 additions & 1 deletion LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Security.SecureString" Version="4.0.0" />
<PackageReference Include="System.IO.UnmanagedMemoryStream" Version="4.0.1" />
<PackageReference Include="System.Diagnostics.TraceSource" Version="4.0.0" />
<PackageReference Include="System.Diagnostics.TraceSource" Version="4.0.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
</ItemGroup>
<Import Project="CodeGenerator.targets" />
<Import Project="ExtraDefine.targets" />
Expand Down