Skip to content

Make location native binary configurable #515

@embix

Description

@embix

When using libgit2sharp from within LinqPad via NuGet, loading the native binary does not work as intended. The executing assembly usually lies somewhere "AppData\Local\Temp\LINQPad\whatever" while all referenced libraries lie elsewhere. CodeBase seems unset for the executing assembly. Thus the type initializer of NativeMethods fails put the correct location into the path:

        static NativeMethods()
        {
            if (!IsRunningOnLinux())
            {
                string originalAssemblypath = new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath;

                string currentArchSubPath = "NativeBinaries/" + ProcessorArchitecture;

                string path = Path.Combine(Path.GetDirectoryName(originalAssemblypath), currentArchSubPath);

                const string pathEnvVariable = "PATH";
                Environment.SetEnvironmentVariable(pathEnvVariable,
                                                   String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", path, Path.PathSeparator, Environment.GetEnvironmentVariable(pathEnvVariable)));
            }

            // See LibraryLifetimeObject description.
            lifetimeObject = new LibraryLifetimeObject();
        }

A workaround is to add the correct path with EnvironMent.SetEnvironmentVariable at application start/composition root which seems a bit odd as it may break when updateing via nuget once again (see: http://stackoverflow.com/a/18867945/303290 ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions