Skip to content

Commit 52de337

Browse files
committed
Change the tree structure into which libgit2 binaries are located in order to be able to dynamically bind against 32 or 64 bits version of libgit2
Should partially fix issue libgit2#70.
1 parent 0200e5f commit 52de337

File tree

9 files changed

+39
-15
lines changed

9 files changed

+39
-15
lines changed

CI-build.msbuild

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,12 @@
3939
<Target Name="Deploy" DependsOnTargets="Test">
4040
<Copy SourceFiles="@(OutputFiles)"
4141
DestinationFiles="@(OutputFiles->'$(DeployFolder)\%(RecursiveDir)%(Filename)%(Extension)')" />
42+
43+
<ItemGroup>
44+
<NativeBinaries Include="$(TestBuildDir)\NativeBinaries\**\*.*" />
45+
</ItemGroup>
46+
47+
<Copy SourceFiles="@(NativeBinaries)"
48+
DestinationFiles="@(NativeBinaries->'$(DeployFolder)\NativeBinaries\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
4249
</Target>
4350
</Project>

Lib/NativeBinaries/amd64/dummy.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Here will be placed the x64 binaries of libgit2
File renamed without changes.
File renamed without changes.

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@
7676
<PreBuildEvent>
7777
</PreBuildEvent>
7878
</PropertyGroup>
79-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
80-
Other similar extension points exist, see Microsoft.Common.targets.
8179
<Target Name="BeforeBuild">
8280
</Target>
8381
<Target Name="AfterBuild">
82+
<ItemGroup>
83+
<NativeBinaries Include="$(MSBuildProjectDirectory)\..\Lib\NativeBinaries\**\*.*" />
84+
</ItemGroup>
85+
<Copy SourceFiles="@(NativeBinaries)" DestinationFiles="@(NativeBinaries->'$(OutputPath)NativeBinaries\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
8486
</Target>
85-
-->
8687
</Project>

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.IO;
3+
using System.Reflection;
24
using System.Runtime.InteropServices;
35

46
namespace LibGit2Sharp.Core
@@ -8,6 +10,20 @@ internal static class NativeMethods
810
public const int GIT_PATH_MAX = 4096;
911
private const string libgit2 = "git2";
1012

13+
static NativeMethods()
14+
{
15+
string originalAssemblypath = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
16+
17+
//TODO: When amd64 version of libgit2.dll is available, value this depending of the size of an IntPtr
18+
const string currentArchSubPath = "NativeBinaries/x86";
19+
20+
string path = Path.Combine(Path.GetDirectoryName(originalAssemblypath), currentArchSubPath);
21+
22+
const string pathEnvVariable = "PATH";
23+
Environment.SetEnvironmentVariable(pathEnvVariable,
24+
String.Format("{0}{1}{2}", path, Path.PathSeparator, Environment.GetEnvironmentVariable(pathEnvVariable)));
25+
}
26+
1127
[DllImport(libgit2)]
1228
public static extern IntPtr git_blob_rawcontent(IntPtr blob);
1329

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,17 @@
121121
<ItemGroup>
122122
<CodeAnalysisDictionary Include="CustomDictionary.xml" />
123123
</ItemGroup>
124-
<ItemGroup>
125-
<None Include="..\Lib\git2.dll">
126-
<Link>git2.dll</Link>
127-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
128-
</None>
129-
</ItemGroup>
130124
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
131125
<PropertyGroup>
132126
<PreBuildEvent>
133127
</PreBuildEvent>
134128
</PropertyGroup>
135-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
136-
Other similar extension points exist, see Microsoft.Common.targets.
137129
<Target Name="BeforeBuild">
138130
</Target>
139131
<Target Name="AfterBuild">
132+
<ItemGroup>
133+
<NativeBinaries Include="$(MSBuildProjectDirectory)\..\Lib\NativeBinaries\**\*.*" />
134+
</ItemGroup>
135+
<Copy SourceFiles="@(NativeBinaries)" DestinationFiles="@(NativeBinaries->'$(OutputPath)NativeBinaries\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
140136
</Target>
141-
-->
142137
</Project>

nuget.package/LibGit2Sharp.nuspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
<tags>libgit2 git wrapper bindings API dvcs vcs</tags>
1313
</metadata>
1414
<files>
15-
<file src="..\Lib\git2.dll" target="NativeBinaries\x86" />
16-
<file src="..\Lib\git2.pdb" target="NativeBinaries\x86" />
15+
<file src="..\Lib\NativeBinaries\**" target="NativeBinaries" />
1716
<file src="..\README.md" target="App_Readme\LibGit2Sharp.README.md" />
1817
<file src="..\LICENSE.md" target="App_Readme\LibGit2Sharp.LICENSE.md" />
1918
<file src="..\CHANGELOG.md" target="App_Readme\LibGit2Sharp.CHANGELOG.md" />

nuget.package/Tools/GetLibGit2SharpPostBuildCmd.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ $path = $installPath.Replace($solutionDir, "`$(SolutionDir)")
33

44
$NativeAssembliesDir = Join-Path $path "NativeBinaries"
55
$x86 = $(Join-Path $NativeAssembliesDir "x86\*.*")
6+
$x64 = $(Join-Path $NativeAssembliesDir "amd64\*.*")
67

78
$LibGit2SharpPostBuildCmd = "
8-
xcopy /s /y `"$x86`" `"`$(TargetDir)`""
9+
if not exist `"`$(TargetDir)NativeBinaries`" md `"`$(TargetDir)NativeBinaries`"
10+
if not exist `"`$(TargetDir)NativeBinaries\x86`" md `"`$(TargetDir)NativeBinaries\x86`"
11+
xcopy /s /y `"$x86`" `"`$(TargetDir)NativeBinaries\x86`"
12+
if not exist `"`$(TargetDir)NativeBinaries\amd64`" md `"`$(TargetDir)NativeBinaries\amd64`"
13+
xcopy /s /y `"$x64`" `"`$(TargetDir)NativeBinaries\amd64`""

0 commit comments

Comments
 (0)