1
votes

When I run locally, GitVersion task works fine and runs. In Azure DevOps build pipeline, the same script fails. I get the following error:

========================================
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

It seems to involve the LibGit2Sharp.Core.NativeMethods library not being there. I thought that the Cake project would download the dlls required if I include:

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

in the Cake build script.

My GitVersion task code is:

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);
});

What am I missing in my code that is not included on the Azure DevOps hosted build agent?

1
What operating system is the hosted build agent?Gary Ewan Park
Should be Windows 10. It is the Hosted VS2017 build agent which is part of Azure DevOps. I believe all of the Windows build agents are Windows 10.Ross Gustafson
Azure DevOps has 3 different windows agents, which one are you using? Hosted Windows 2019 with VS 2019, Hosted VS2017 (Server 2016), Hosted (Server 2012)devlead
@devlead I figured it out. It was the gitignore file ignoring those dlls because it was ignore all x86 and x64 folders in the repo.Ross Gustafson

1 Answers

1
votes

So I figured out the issue. I had a .gitignore file which removes the x86 and x64 folders from the git commits. Well, GitVersion command line tool's Windows dll files are in those named folders under the win32 folder. Therefore, the tool and all its subfolders were committed to the repo except for those dlls so when cake ran, it thought the tool was there but the dlls were missing. I manually forced those dlls and their folders to be committed which solved it.

What I really should do is remove and then .gitignore all of the files in the tools directory which holds cake build and its tools except for the packages.config file so that each time we run the automatied build it should get fresh copy of cake and the tools. But that is a design decision.

So a warning to the wise, if you are missing dlls or files, check to see if gitignore file is remove those files and/or any of its parent folders.