The type initializer for 'LibGit2Sharp.Core.NativeMethods’ threw an exception. | TFS Build Server

In my case it was related with „gated checkin” TFS continuous delivery option on Remote Deploy. The workaround is to add /p:GenerateBuildInfoConfigFile=false to the msbuild arguments in your build definition. 

Here are similar issue with Azure Deployments:

https://stackoverflow.com/questions/29286052/tfs-2013-throws-lib2gitsharp-error-during-build-deploy-intermittent