microsoft / VSExtensibility

A repo for upcoming changes to extensibility in Visual Studio, the new extensibility model, and language server protocol.
MIT License
351 stars 42 forks source link

Exception when using/referencing packages with native libraries #390

Open luislhg opened 3 weeks ago

luislhg commented 3 weeks ago

Hello, I'm trying to develop an extension that uses libgit2sharp, which has native libraries. It fails when trying to use it with this exception

The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.

InnerException = {"Unable to load DLL 'git2-a418d9d' or one of its dependencies: Não foi possível encontrar o módulo especificado. (0x8007007E)"}

Here is a reproduceable project, it's very simple, just added a nuget reference to a package using native libraries, and this fails in the extension project. It works nicely in a console project for example. ExtensibilityNativeLibraries.zip

matteo-prosperi commented 1 week ago

Most likely LibGit2Sharp is not able to find the assembly since it's not in the running executable folder. I have never used LibGit2Sharp myself but, from a quick search on the internet, you could try to set LibGit2Sharp.GlobalSettings.NativeLibraryPath (see here).

luislhg commented 1 week ago

That being said, aren't all libraries supposed to be embedded into the vsix? How would I specify a NativeLibraryPath in the first place if the users wont have that native library anywhere in their computers?

In the post's sample project, the debug/release folder will have the native libraries as expected, but once loaded into VS via VSIX, native libraries are not there (or are not found) and it doesn't work inside the extension.