运行时,Cake Build脚本中的GitVersion任务缺少Azure DevOps上的库

时间:2019-04-04 14:38:45

标签: azure-devops cakebuild gitversion

当我在本地运行时,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托管生成代理中的代码中缺少什么?

1 个答案:

答案 0 :(得分:0)

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

我真正应该做的是先删除,然后.gitignore除去包含cake build及其工具的tools目录中的所有文件(packages.config文件除外),这样,每次我们运行自动构建时,它都应该获得新副本蛋糕和工具。但这是设计决定。

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

相关问题