我有带有LINQPad的NuGet版本,并添加了libgit2sharp,但这依赖于另一个(本机) dll。
我试过:
Assembly.GetExecutingAssembly().Location时复制它们我只是尝试用这个库读取日志,并将它作为LINQPad中的一个片段来阅读,虽然我认为如果其他程序都失败了,我可以将它变成一个控制台应用程序。
有人使用libgit2sharp和LINQPad,并能解释如何让他们在一起玩得很好?
发布于 2013-06-07 12:58:40
将dll放入路径中的文件夹或将dll的位置添加到路径中应该可以工作(并且适合我)
也许你的改变还没有生效。尝试关闭并重新打开LinqPad,如果失败,请退出并返回窗口。
发布于 2016-10-09 07:11:46
编辑:LINQPad再次支持开箱即用( LINQPad 5.10.02 -在写文章时的测试版)。现在不需要任何解决办法。
不幸的是,这在LibGit2Sharp v0.22中又被破坏了。此包不再包含LibGit2Sharp.dll位于/libs中的子文件夹中的本机二进制文件。相反,它们位于一个独立的依赖NuGet包中,该包依赖于修补项目文件。由于LINQPad不使用项目文件,这将失败。
您可以按照其他答案中的建议添加一个初始化方法来填充本机文件夹位置的路径变量,从而解决这一问题。以下代码将在任何具有当前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);
}
}注意,您不需要显式调用此方法,因为它位于静态构造函数中。
另一个解决方法是在NuGet上发布另一个NuGet包,其中包括LibGit2Sharp.dll所在的预期位置下的本机二进制文件(NativeBinarisx86\git2-785d8c4.dll和NativeBinaries\ and 86\git2-785d8c4.dll)-例如下载LibGit2Sharp 0.21.0.176。
发布于 2013-09-18 09:01:19
最后,我在运行时添加了相关路径,使用:
void SetUpNativeBinaries(){
var appDataLocal = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var packageVersion = "LibGit2Sharp.0.14.0.0";// may read from PackageInfo
var processorArchitecture = IntPtr.Size==8?"amd64":"x86";
var libgitNativeBinaryPath = Path.Combine(appDataLocal, "LINQPad", "NuGet", "LibGit2Sharp", packageVersion, "NativeBinaries", processorArchitecture);
libgitNativeBinaryPath.Dump();
var pathEnvVariable = "PATH";
var currentPaths = Environment.GetEnvironmentVariable(pathEnvVariable);
var combinedPaths = String.Format(
System.Globalization.CultureInfo.InvariantCulture,
"{0}{1}{2}",
libgitNativeBinaryPath,
Path.PathSeparator,
currentPaths);
Environment.SetEnvironmentVariable(pathEnvVariable, combinedPaths);
}将其保存为"C#程序“,您可以立即开始:
void Main()
{
SetUpNativeBinaries();
var repoWorkingDir = @"C:\temp\libgit2_repo";
var repo = new Repository(repoWorkingDir);
repo.Config.Dump();
repo.Branches.Dump();
repo.Index.RetrieveStatus().Dump();
//...
}https://stackoverflow.com/questions/16983085
复制相似问题