Cake.git 插件在 Windows 10 中抛出异常

Cake.git addin throw exception in Windows 10

我有一个 .NET Standard 项目,我想用 Cake 为这个项目创建一个构建脚本。我从 Cake 的资源下载 build.ps1 并将其移动到 Build 目录,然后创建了一个 build.cake 文件如下:

#addin nuget:?package=Nuget.Core
#addin nuget:?package=Cake.Git&version=0.19.0
//#addin "nuget:?package=Cake.Coveralls&version=0.9.0"

using NuGet;

var target = Argument("target", "Default");
var artifactsDir = "./artifacts/";
var solutionPath = "../BSN.Commons.sln";
var project = "../Source/BSN.Commons.csproj";
var testFolder = "../Test/BSN.Commons.Tests/";
var testProject = testFolder + "BSN.Commons.Tests.csproj";
var coverageResultsFileName = "coverage.xml";
var currentBranch = Argument<string>("currentBranch", GitBranchCurrent("./").FriendlyName);

Task("Restore")
    .Does(() => {
        DotNetCoreRestore(solutionPath);
});

在我运行之后:

./build.ps1 -script build.cake --currentBranch=develop --nugetApiKey=g234234 --coverallsToken=234234 --verbosity=Diagnostic

我看到类似下面的日志

Running build script...
Module directory does not exist.
NuGet.config not found.
Analyzing build script...
Analyzing D:/Users/sooro/Source/Repos/soroshsabz/Commons/Build/build.cake...
Processing build script...
Installing addins...
  CACHE https://api.nuget.org/v3/registration3-gz-semver2/nuget.core/index.json
Found package 'Nuget.Core 2.14.0' in 'D:/Users/sooro/Source/Repos/soroshsabz/Commons/Build/tools/Addins'.
Package NuGet.Core.2.14.0 has already been installed.
Successfully installed 'Nuget.Core 2.14.0' to D:/Users/sooro/Source/Repos/soroshsabz/Commons/Build/tools/Addins
Executing nuget actions took 37.63 ms
The addin Nuget.Core will reference NuGet.Core.dll.
Found package 'Cake.Git 0.19.0' in 'D:/Users/sooro/Source/Repos/soroshsabz/Commons/Build/tools/Addins'.
Package Cake.Git.0.19.0 has already been installed.
Successfully installed 'Cake.Git 0.19.0' to D:/Users/sooro/Source/Repos/soroshsabz/Commons/Build/tools/Addins
Executing nuget actions took 4.37 ms
The addin Cake.Git will reference LibGit2Sharp.dll.
The addin Cake.Git will reference Cake.Git.dll.
Verifying assembly 'NuGet.Core, Version=2.14.0.832, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Verifying assembly 'LibGit2Sharp, Version=0.25.0.0, Culture=neutral, PublicKeyToken=7cbde695407f0333'.
Verifying assembly 'Cake.Git, Version=0.19.0.0, Culture=neutral, PublicKeyToken=null'.
Compiling build script...
Error: System.AggregateException: One or more errors occurred. ---> System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'git2-6311e88': A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)
   at LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
   at LibGit2Sharp.Core.NativeMethods.LoadNativeLibrary()
   at LibGit2Sharp.Core.NativeMethods..cctor()
   --- End of inner exception stack trace ---
   at LibGit2Sharp.Core.NativeMethods.git_repository_open(git_repository*& repository, FilePath path)
   at LibGit2Sharp.Core.Proxy.git_repository_open(String path)
   at LibGit2Sharp.Repository..ctor(String path, RepositoryOptions options, RepositoryRequiredParameter requiredParameter)
   at Cake.Git.Extensions.RepositoryExtensions.UseRepository[TResult](ICakeContext context, DirectoryPath repositoryPath, Func`2 repositoryFunc)
   at Cake.Git.GitAliases.GitBranchCurrent(ICakeContext context, DirectoryPath repositoryDirectoryPath)
   at Submission#0.GitBranchCurrent(DirectoryPath repositoryDirectoryPath)
   at Submission#0.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---

为什么抛出一些异常?我该如何解决?

这是由于 .NET Framework 上的网络标准问题,需要新版本的 libgit2sharp。我们有一个正在测试的预发布版本,之前的版本 Cake.Git 可能会工作。