I am working on a vsix project where I need to get information about a local git directory. I am following this article. When I am using LibGit2Sharp
library, I am getting an exception as described in following image and error:-
How can I resolve this?
VS version details:
Visual Studio 2019
.Net Framework 4.7.2
LibGit2Sharp is a managed language (.NET) wrapper around a native (C) library, libgit2. It's a P/Invoke layer, plus a layer to give .NET semantics (objects, etc). This means, though, that you require both the LibGit2Sharp.dll (the managed-language side) and the git2-xxxxxxx.dll
(the corresponding native library) that it calls into.
The native DLL is part of the LibGit2Sharp.NativeBinaries project that LibGit2Sharp takes a dependency on. It should be installed (transitively) when you install LibGit2Sharp itself. And although it tries to set itself up as a dependency that will be installed in the output directory, since native binaries are not well-understood in the .NET project world, this can sometimes fail, especially for more complex project types like VSIX.
Ultimately, LibGit2Sharp will look for the corresponding native DLL alongside where it's located. So within your output directory, wherever your VSIX is being executed from, try copying the git2-xxxxxxx.dll
that is part of the LibGit2Sharp.NativeBinaries project to that location.
Once you've identified the correct location for the git2-xxxxxxx.dll
binary to live, you should copy this as part of your installation for the project. (eg Build action: None, Copy to output directory: Copy always)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With