Don*_*Don 6 linqpad libgit2sharp
我有使用NuGet的LINQPad版本,我添加了libgit2sharp,但这依赖于另一个(本机)dll.
我试过了:
Assembly.GetExecutingAssembly().Location我只是试图用这个库读取日志并将其作为LINQPad中的片段将是整洁的虽然我想我可以使它成为一个控制台应用程序,如果所有其他失败.
任何人都使用libgit2sharp和LINQPad,可以解释如何让它们一起玩得很好吗?
将dll放入路径中的文件夹或将dll的位置添加到路径中应该有效(并且对我有用)
也许你的改变没有生效.尝试关闭并重新打开LinqPad,如果失败,请退出并返回到Windows.
编辑:LINQPad再次开箱即用地支持LibGit2Sharp(从LINQPad 5.10.02开始-撰写本文时为beta)。现在不需要任何解决方法。
不幸的是,这在LibGit2Sharp v0.22中再次被打破。此软件包不再在/ libs中位于LibGit2Sharp.dll的子文件夹中包含本机二进制文件。相反,它们位于单独的依赖NuGet程序包中,该程序包依赖于修补项目文件。由于LINQPad不使用项目文件,因此失败。
您可以通过添加其他答案中建议的初始化方法来解决此问题,以使用本地文件夹位置填充PATH变量。以下代码无需修改即可在使用当前LibGit2Sharp的任何计算机上运行:
void Main()
{
... your query here...
}
static UserQuery()
{
const string pathEnvVariable = "PATH";
char slash = Path.DirectorySeparatorChar;
char pathSep = Path.PathSeparator;
// The correct native binary file is located under a folder ending in
// "windows\x86" or "windows\amd64" or "win7-x86\native" or "win7-x64\native".
// This may change in later LibGit2Sharp releases.
string nativeStem1 = $"{slash}windows{slash}{(IntPtr.Size == 8 ? "amd64" : "x86")}";
string nativeStem2 = $"{(IntPtr.Size == 8 ? "-x64" : "-x86")}{slash}native";
// Locate the root folder in the NuGet package. This contains folders for the
// main package (LibGit2Sharp) plus dependencies (LibGit2Sharp.NativeBinaries).
var nugetRoot = new FileInfo (typeof (Repository).Assembly.Location)
.Directory.Parent.Parent.Parent;
var nativeBinaryPath = nugetRoot
.GetFiles ("*.dll", SearchOption.AllDirectories)
.Single (d => d.DirectoryName.EndsWith (nativeStem1, StringComparison.OrdinalIgnoreCase) ||
d.DirectoryName.EndsWith (nativeStem2, StringComparison.OrdinalIgnoreCase))
.Directory
.FullName;
string currentPaths = Environment.GetEnvironmentVariable (pathEnvVariable);
if (!(pathSep + currentPaths + pathSep).ToUpperInvariant().Contains
(pathSep + nativeBinaryPath.ToUpperInvariant() + pathSep))
{
Environment.SetEnvironmentVariable (pathEnvVariable, currentPaths + pathSep + nativeBinaryPath);
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,您不需要显式调用此方法,因为它在静态构造函数中。
另一个解决方法是在NuGet上发布另一个LibGit2Sharp程序包,该程序包在LibGit2Sharp.dll所在的预期位置(NativeBinaries \ x86 \ git2-785d8c4.dll和NativeBinaries \ amd86 \ git2-785d8c4.dll)中包含本地二进制文件。例如LibGit2Sharp 0.21.0.176。