From 596cc3a4c284e6baee9984347244de8ac3a61a76 Mon Sep 17 00:00:00 2001 From: Jacek Blaszczynski Date: Sat, 16 May 2026 22:39:21 +0200 Subject: [PATCH 1/5] build: align target framework and unify native interop with parent Migrate all projects to target .NET 10.0 exclusively, removing legacy target frameworks. Implement dynamic MSBuild inheritance by injecting Directory.Build.props and .targets to pull configuration from the parent repository root. Disable internal NativeLibrary.SetDllImportResolver logic in NativeMethods. Native dependency resolution is now deferred entirely to the cross-platform module initializer managed by the parent DjvuNet build tasks. Modernize cryptographic API usage in CertificateX509 by migrating from the deprecated X509Certificate byte array constructor to the secure X509CertificateLoader.LoadCertificate method. Expose assembly internals to DjvuNet testing projects via a generated AssemblyInfo template. Signed-off-by: Jacek Blaszczynski --- .gitignore | 2 ++ Directory.Build.props | 3 +- Directory.Build.targets | 5 +++ LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 2 +- LibGit2Sharp/CertificateX509.cs | 2 +- LibGit2Sharp/Core/NativeMethods.cs | 2 +- LibGit2Sharp/LibGit2Sharp.csproj | 32 +++++++++++-------- .../Properties/AssemblyInfo.Template.cs | 26 +++++++++++++++ .../x64/NativeLibraryLoadTestApp.x64.csproj | 2 +- .../x86/NativeLibraryLoadTestApp.x86.csproj | 2 +- 10 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 Directory.Build.targets create mode 100644 LibGit2Sharp/Properties/AssemblyInfo.Template.cs diff --git a/.gitignore b/.gitignore index 32e17b4d0..e16a0b461 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,5 @@ _ReSharper*/ _NCrunch_LibGit2Sharp/ artifacts/ worktree.playlist +**/Properties/AssemblyInfo.net*.cs +**/Properties/AssemblyInfoCommon.net*.cs diff --git a/Directory.Build.props b/Directory.Build.props index 2c14cc2bd..999f8f1e6 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -3,7 +3,6 @@ true true - true $(DefineConstants);$(ExtraDefine) @@ -11,4 +10,6 @@ true + + diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 000000000..f98e4abdc --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index fb81a76a3..b55c95362 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -1,7 +1,7 @@  - net472;net8.0;net9.0 + net10.0 diff --git a/LibGit2Sharp/CertificateX509.cs b/LibGit2Sharp/CertificateX509.cs index 7b5b0fac6..f855584f1 100644 --- a/LibGit2Sharp/CertificateX509.cs +++ b/LibGit2Sharp/CertificateX509.cs @@ -26,7 +26,7 @@ internal unsafe CertificateX509(git_certificate_x509* cert) int len = checked((int)cert->len.ToUInt32()); byte[] data = new byte[len]; Marshal.Copy(new IntPtr(cert->data), data, 0, len); - Certificate = new X509Certificate(data); + Certificate = X509CertificateLoader.LoadCertificate(data); } internal CertificateX509(X509Certificate cert) diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index cbb850b16..28b90a254 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -73,7 +73,7 @@ private static string GetGlobalSettingsNativeLibraryPath() #else private static bool TryUseNativeLibrary() { - NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, ResolveDll); + //NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, ResolveDll); return true; } diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 1c4abef7b..e5d96e105 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -1,8 +1,9 @@  - net472;net8.0 - 12.0 + net10.0 + true + false true LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .NET LibGit2Sharp contributors @@ -12,25 +13,32 @@ LibGit2Sharp contributors true true - embedded true - ..\libgit2sharp.snk + $(RepoRootDir)Snk.snk square-logo.png App_Readme/README.md App_Readme/LICENSE.md true - $(ArtifactsPath)\package + $(OutputPath)\package preview.0 libgit2-$(libgit2_hash.Substring(0,7)) - + true + $(NoWarn);NU5128 - - + + + + + + + + + @@ -52,10 +60,6 @@ - - - $(MinVerMajor).$(MinVerMinor).0.0 - - + - + diff --git a/LibGit2Sharp/Properties/AssemblyInfo.Template.cs b/LibGit2Sharp/Properties/AssemblyInfo.Template.cs new file mode 100644 index 000000000..961a3cdce --- /dev/null +++ b/LibGit2Sharp/Properties/AssemblyInfo.Template.cs @@ -0,0 +1,26 @@ +// TEMPLATE:.+ + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("LibGit2Sharp")] +[assembly: AssemblyDefaultAlias("LibGit2Sharp")] +[assembly: AssemblyDescription("LibGit2Sharp Library for handling of Git repositories.")] +[assembly: AssemblyConfiguration("__LIBRARY_CONFIGURATION__")] +[assembly: AssemblyPlatform("__LIBRARY_PLATFORM__")] +[assembly: AssemblyCulture("")] + + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("107A6B04-09CB-4ADD-87E0-5B5DF0B09BFE")] + + +[assembly: InternalsVisibleTo("DjvuNet.Tests,PublicKey=00240000048000009400000006020000002400005253413100040000010001004dc7a384af8b33357ae286a9c208740e12580e26c93cfc529e38460986c19e382c23406f34eca0bf2baae3e9d69157c1f66675ac0d419c39028e070fcb687935aae49ee53cc85ea3faed79aeefe48f25a97ccecf02d983b2d71e92b7ebd71eb109b886b2cafa5cc9c8e915c6b802d0e975b44a7a5252c5693e8fa53a49fc36c2")] +[assembly: InternalsVisibleTo("DjvuNet.Helper.Tests,PublicKey=00240000048000009400000006020000002400005253413100040000010001004dc7a384af8b33357ae286a9c208740e12580e26c93cfc529e38460986c19e382c23406f34eca0bf2baae3e9d69157c1f66675ac0d419c39028e070fcb687935aae49ee53cc85ea3faed79aeefe48f25a97ccecf02d983b2d71e92b7ebd71eb109b886b2cafa5cc9c8e915c6b802d0e975b44a7a5252c5693e8fa53a49fc36c2")] +[assembly: InternalsVisibleTo("DjvuNet.Wavelet.Tests,PublicKey=00240000048000009400000006020000002400005253413100040000010001004dc7a384af8b33357ae286a9c208740e12580e26c93cfc529e38460986c19e382c23406f34eca0bf2baae3e9d69157c1f66675ac0d419c39028e070fcb687935aae49ee53cc85ea3faed79aeefe48f25a97ccecf02d983b2d71e92b7ebd71eb109b886b2cafa5cc9c8e915c6b802d0e975b44a7a5252c5693e8fa53a49fc36c2")] +[assembly: InternalsVisibleTo("DjvuNet.DjvuLibre.Tests,PublicKey=00240000048000009400000006020000002400005253413100040000010001004dc7a384af8b33357ae286a9c208740e12580e26c93cfc529e38460986c19e382c23406f34eca0bf2baae3e9d69157c1f66675ac0d419c39028e070fcb687935aae49ee53cc85ea3faed79aeefe48f25a97ccecf02d983b2d71e92b7ebd71eb109b886b2cafa5cc9c8e915c6b802d0e975b44a7a5252c5693e8fa53a49fc36c2")] +[assembly: InternalsVisibleTo("DjvuNetTest,PublicKey=00240000048000009400000006020000002400005253413100040000010001004dc7a384af8b33357ae286a9c208740e12580e26c93cfc529e38460986c19e382c23406f34eca0bf2baae3e9d69157c1f66675ac0d419c39028e070fcb687935aae49ee53cc85ea3faed79aeefe48f25a97ccecf02d983b2d71e92b7ebd71eb109b886b2cafa5cc9c8e915c6b802d0e975b44a7a5252c5693e8fa53a49fc36c2")] diff --git a/NativeLibraryLoadTestApp/x64/NativeLibraryLoadTestApp.x64.csproj b/NativeLibraryLoadTestApp/x64/NativeLibraryLoadTestApp.x64.csproj index 3bca18b34..afcfcf592 100644 --- a/NativeLibraryLoadTestApp/x64/NativeLibraryLoadTestApp.x64.csproj +++ b/NativeLibraryLoadTestApp/x64/NativeLibraryLoadTestApp.x64.csproj @@ -2,7 +2,7 @@ Exe - net472 + net10.0 x64 diff --git a/NativeLibraryLoadTestApp/x86/NativeLibraryLoadTestApp.x86.csproj b/NativeLibraryLoadTestApp/x86/NativeLibraryLoadTestApp.x86.csproj index 0596f203c..6a921f228 100644 --- a/NativeLibraryLoadTestApp/x86/NativeLibraryLoadTestApp.x86.csproj +++ b/NativeLibraryLoadTestApp/x86/NativeLibraryLoadTestApp.x86.csproj @@ -2,7 +2,7 @@ Exe - net472 + net10.0 x86 From 7f38fa816f3964745fc4064c3a087194814693b4 Mon Sep 17 00:00:00 2001 From: Jacek Blaszczynski Date: Tue, 19 May 2026 01:50:20 +0200 Subject: [PATCH 2/5] build: enforce AnyCPU targeting to fix deps.json generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During the DjvuNet CI migration to GitHub Actions, the custom MSBuild tasks dependent on LibGit2Sharp failed to load on ARM64 architectures. This was traced to LibGit2Sharp inheriting global platform properties (like RuntimeIdentifier or Platform) from the parent CI build process, which corrupted the generated deps.json file and prevented native binary resolution. Explicit AnyCPU platform enforcement and TreatAsLocalProperty directives have been added to the project file. This ensures the library strictly compiles as a platform-agnostic artifact and correctly resolves its cross-platform native dependencies at runtime, regardless of the outer build environment. Signed-off-by: Jacek Błaszczyński --- LibGit2Sharp/LibGit2Sharp.csproj | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index e5d96e105..8acc6e134 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -1,4 +1,10 @@ - + + + + + AnyCPU + AnyCPU + net10.0 From 6b4c98c5aa36565ad5e8378ebc276922e2949f89 Mon Sep 17 00:00:00 2001 From: Jacek Blaszczynski Date: Mon, 8 Jun 2026 23:57:49 +0200 Subject: [PATCH 3/5] docs: update README.md Signed-off-by: Jacek Blaszczynski --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 96aa2bbd1..84c6b1b89 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # LibGit2Sharp -[![CI](https://github.com/libgit2/libgit2sharp/actions/workflows/ci.yml/badge.svg)](https://github.com/libgit2/libgit2sharp/actions/workflows/ci.yml) +[![CI](https://github.com/libgit2/libgit2sharp/actions/workflows/ci.yml/badge.svg)](https://github.com/libgit2/libgit2sharp/actions/workflows/ci.yml) [![NuGet version (LibGit2Sharp)](https://img.shields.io/nuget/v/LibGit2Sharp.svg)](https://www.nuget.org/packages/LibGit2Sharp/) **LibGit2Sharp brings all the might and speed of [libgit2](https://libgit2.org/), a native Git implementation, to the managed world of .NET** +## Fork used by DjvuNet project + ## Online resources - [NuGet package](http://nuget.org/List/Packages/LibGit2Sharp) From fc542b103fc0469336f950ea6b2eed3f811827c0 Mon Sep 17 00:00:00 2001 From: Jacek Blaszczynski Date: Tue, 16 Jun 2026 21:12:55 +0200 Subject: [PATCH 4/5] infra: restore Visual Studio tooling support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Restore Visual Studio IDE tooling support by building versioned tooling against net10.0 and net472. Its required to run DjvuNet.Build.Tasks in-process while MSbuild netfx version is used by VS to work with managed code. Signed-off-by: Jacek Błaszczyński --- LibGit2Sharp/CertificateX509.cs | 8 ++++++-- LibGit2Sharp/LibGit2Sharp.csproj | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/LibGit2Sharp/CertificateX509.cs b/LibGit2Sharp/CertificateX509.cs index f855584f1..7173f609e 100644 --- a/LibGit2Sharp/CertificateX509.cs +++ b/LibGit2Sharp/CertificateX509.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Runtime.InteropServices; using System.Security.Cryptography.X509Certificates; using LibGit2Sharp.Core; @@ -26,7 +26,11 @@ internal unsafe CertificateX509(git_certificate_x509* cert) int len = checked((int)cert->len.ToUInt32()); byte[] data = new byte[len]; Marshal.Copy(new IntPtr(cert->data), data, 0, len); - Certificate = X509CertificateLoader.LoadCertificate(data); +#if NETCOREAPP + Certificate = X509CertificateLoader.LoadCertificate(data); +#else + Certificate = new X509Certificate(data); +#endif } internal CertificateX509(X509Certificate cert) diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 8acc6e134..79a1d710a 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -30,6 +30,11 @@ libgit2-$(libgit2_hash.Substring(0,7)) + + + net10.0;net472 + + true $(NoWarn);NU5128 From 492caaaaec30a2a0bf7234ae2eec8cc15aee96c2 Mon Sep 17 00:00:00 2001 From: Jacek Blaszczynski Date: Thu, 6 Aug 2026 10:48:07 +0200 Subject: [PATCH 5/5] docs: document DjvuNet fork modifications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update the README to explicitly document the modifications made for the DjvuNet project. This explains the fork's support for easy OS and platform multitargeting, reliable native dependency resolution, and shared build directories across different OSes and clients (e.g., Windows and WSL). Signed-off-by: Jacek Błaszczyński --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 84c6b1b89..f5deb47e0 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ ## Fork used by DjvuNet project +This repository is modified for easy OS and platform multitargeting and reliable, improved native dependency resolution during runtime. It also supports sharing the same build directory between different OSes and platforms when used during the build process as a universal build tool. It supports scenarios like network share usage from different clients and Windows/WSL directory sharing. + ## Online resources - [NuGet package](http://nuget.org/List/Packages/LibGit2Sharp)