1

当我在本地运行时,GitVersion 任务工作正常并运行。在 Azure DevOps 构建管道中,相同的脚本失败。我收到以下错误:

========================================
Version
========================================
Executing task: Version
INFO [04/03/19 20:23:54:54] Working directory: D:\a\1\s\PPIL
INFO [04/03/19 20:23:54:56] IsDynamicGitRepository: False
ERROR [04/03/19 20:23:54:60] An unexpected error occurred:
System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'git2-15e1193': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   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_buf_free(GitBuf buf)
   at LibGit2Sharp.Core.Handles.GitBuf.Dispose()
   at LibGit2Sharp.Core.Proxy.ConvertPath(Func`2 pathRetriever)
   at LibGit2Sharp.Repository.Discover(String startingPath)
   at GitVersion.GitPreparer.GetDotGitDirectory()
   at GitVersion.GitPreparer.GetProjectRootDirectory()
   at GitVersion.ConfigurationProvider.Verify(GitPreparer gitPreparer, IFileSystem fileSystem)
   at GitVersion.Program.VerifyArgumentsAndRun()
INFO [04/03/19 20:23:54:60] 
INFO [04/03/19 20:23:54:60] Attempting to show the current git graph (please include in issue): 
INFO [04/03/19 20:23:54:60] Showing max of 100 commits
INFO [04/03/19 20:23:54:64] *   c27bbc5 5 minutes ago  (HEAD, origin/master)
|\  
| * 57526a4 11 minutes ago 
|/  
*   5057bd8 63 minutes ago 
|\  
| * 3df4426 68 minutes ago 
|/  
*   9e7d5bc 6 days ago 
|\  
| * 222a7e0 6 days ago 
|/  
*   3474e55 6 days ago 
|\  
| * 9156567 6 days ago 
| * 043e8be 6 days ago 
|/  
| * d4394a6 2 days ago  (origin/serilog)
|/  
* 888471a 7 days ago 
*   17c9ee3 2 weeks ago 
|\  
| * 9f61e42 2 weeks ago 
| * 02e6828 2 weeks ago 
| * 62dd884 3 weeks ago 
|/  
*   b71f0e2 4 weeks ago 
|\  
| * a040103 4 weeks ago 
| * 45a773c 4 weeks ago 
|/  
* 6ac1314 5 weeks ago 
* 3f81960 5 weeks ago 
* 8ea9f85 5 weeks ago 
* c9bb4ee 5 weeks ago 

INFO [04/03/19 20:23:54:54] Working directory: D:\a\1\s\PPIL
INFO [04/03/19 20:23:54:56] IsDynamicGitRepository: False
ERROR [04/03/19 20:23:54:60] An unexpected error occurred:
System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'git2-15e1193': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   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_buf_free(GitBuf buf)
   at LibGit2Sharp.Core.Handles.GitBuf.Dispose()
   at LibGit2Sharp.Core.Proxy.ConvertPath(Func`2 pathRetriever)
   at LibGit2Sharp.Repository.Discover(String startingPath)
   at GitVersion.GitPreparer.GetDotGitDirectory()
   at GitVersion.GitPreparer.GetProjectRootDirectory()
   at GitVersion.ConfigurationProvider.Verify(GitPreparer gitPreparer, IFileSystem fileSystem)
   at GitVersion.Program.VerifyArgumentsAndRun()
INFO [04/03/19 20:23:54:60] 
INFO [04/03/19 20:23:54:60] Attempting to show the current git graph (please include in issue): 
INFO [04/03/19 20:23:54:60] Showing max of 100 commits
INFO [04/03/19 20:23:54:64] *   c27bbc5 5 minutes ago  (HEAD, origin/master)
|\  
| * 57526a4 11 minutes ago 
|/  
*   5057bd8 63 minutes ago 
|\  
| * 3df4426 68 minutes ago 
|/  
*   9e7d5bc 6 days ago 
|\  
| * 222a7e0 6 days ago 
|/  
*   3474e55 6 days ago 
|\  
| * 9156567 6 days ago 
| * 043e8be 6 days ago 
|/  
| * d4394a6 2 days ago  (origin/serilog)
|/  
* 888471a 7 days ago 
*   17c9ee3 2 weeks ago 
|\  
| * 9f61e42 2 weeks ago 
| * 02e6828 2 weeks ago 
| * 62dd884 3 weeks ago 
|/  
*   b71f0e2 4 weeks ago 
|\  
| * a040103 4 weeks ago 
| * 45a773c 4 weeks ago 
|/  
* 6ac1314 5 weeks ago 
* 3f81960 5 weeks ago 
* 8ea9f85 5 weeks ago 
* c9bb4ee 5 weeks ago 

##[error]An error occurred when executing task 'Version'.
##[error]Error: One or more errors occurred.
##[error]   GitVersion: Process returned an error (exit code 1).
##[error]System.Exception: Unexpected exit code 1 returned from tool Cake.exe
   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.InvokeToolCmdlet.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
##[error]PowerShell script completed with 1 errors.
##[section]Finishing: Integration Layer Cake

它似乎涉及不存在的LibGit2Sharp.Core.NativeMethods库。我认为如果我包含以下内容,Cake 项目会下载所需的 dll:

#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0"

在 Cake 构建脚本中。

我的 GitVersion 任务代码是:

GitVersion versionInfo = null;
Task("Version")
    .Does(() => {
    GitVersion(new GitVersionSettings{
        UpdateAssemblyInfo = true,
        OutputType = GitVersionOutput.BuildServer
    });
    versionInfo = GitVersion(new GitVersionSettings{ OutputType = GitVersionOutput.Json });

    Information("Version info: " + versionInfo.InformationalVersion);
});

我在 Azure DevOps 托管生成代理中未包含的代码中缺少什么?

4

1 回答 1

1

所以我想通了这个问题。我有一个 .gitignore 文件,它从 git 提交中删除了 x86 和 x64 文件夹。好吧,GitVersion 命令行工具的 Windows dll 文件在 win32 文件夹下的那些命名文件夹中。因此,除了那些 dll 之外,该工具及其所有子文件夹都已提交到 repo,因此当 cake 运行时,它认为该工具在那里,但 dll 丢失了。我手动强制提交这些 dll 及其文件夹,从而解决了这个问题。

我真正应该做的是删除然后 .gitignore 保存蛋糕构建及其工具的工具目录中的所有文件,packages.config 文件除外,这样每次我们运行自动构建时,它应该得到蛋糕的新副本和工具。但这是一个设计决定。

因此,明智的警告是,如果您缺少 dll 或文件,请检查 gitignore 文件是否删除了这些文件和/或其任何父文件夹。

于 2019-04-04T23:32:53.813 回答