So, I'm using GitVersionTask in my Docker build (using the officical microsoft/dotnet:2.1-sdk image). The issue I was having is the following error:
Could not determine assembly version: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'git2-15e1193' or one of its dependencies.
How I fixed it, is by install the library system wide and symlinking the location it's searching (used the LD_DEBUG env var to check what it was doing). In my Dockerfile I now have:
FROM microsoft/dotnet:2.1-sdk as builder
# Fix GitVersionTask build issue
RUN apt-get update && \
apt-get install -y libgit2-dev && \
ln -s /usr/lib/x86_64-linux-gnu/libgit2.so /lib/x86_64-linux-gnu/libgit2-15e1193.so
.... other build steps
I created the issue just to let you know. The current version (15e1193) is hardcoded above, so it might change depending on the LibGit2Sharp.Core.NativeMethods library version is used.
How are you using GitVersionTask inside this docker image? Can u share pls ?
How are you using GitVersionTask inside this docker image? Can u share pls ?
Just install the NuGet package GitVersionTask (I have version 4.0.0-beta0014 installed) and build your project. Check the output dll file and you'll see the assembly version has been updated.
For running on net.core 2.1.0 perhaps it's because you need https://github.com/GitTools/GitVersion/pull/1422 ?
@gerwim can you validate this agains the latest v.4.0.0 version and close the issue ? Thanks
@arturcic I've installed GitVersionTask 4.0.0 and tried the build the project inside the microsoft/dotnet:2.1-sdk docker image, but still same error. I also tried to install libgit2-dev without symlinking the libraries, but to no avail:
MSBUILD : warning : WARN [10/23/18 7:59:06:37] Could not determine assembly version: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'git2-15e1193' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libgit2-15e1193: cannot open shared object file: No such file or directory
As above, I think you need the .net core 2.1 support which is in #1422 and not yet merged..
Otherwise try with a net core sdk 2.0 docker image.
@dazinator Yeah, that's what I thought however Artur explicitly asked me to redo the test with the 2.1 version. Either way, let's wait until the PR is merged. ;-)
I did that because the docker images that we currently have for version 4.0.0 are using microsoft/dotnet:2.1-runtime and they do work.
@arturcic my guess is that the docker images we have currently for 2.1.0 are just calling dotnet gitversion which is slightly different from calling dotnet build (or msbuild) within the image to build a csproj file under dotnet sdk 2.1.0 cli, which loads and executes GitVersionTask. As far as I know the PR in question enables GitVersionTask to run in that second scenario. If things already work fine on 2.1.0 (including gitversiontask) then it would make me question the purpose of that outstanding PR..
you're absolutely right
We should probably rename that PR to make it super clear that its a gitversiontask thing. GitVersion itself already runs on 2.1.0 as you have said! But i think there may have been some other changes in it like the global tool stuff so I guess its now more of a conglomorate of things :-)
I have the same problem, here is a sample Dockerfile:
FROM microsoft/dotnet:sdk
WORKDIR /app
RUN dotnet new console
RUN dotnet add package GitVersionTask
RUN dotnet build
At this time I tested it sdk is equivalent to 2.1.403-sdk-stretch 2.1-sdk-stretch 2.1.403-sdk 2.1-sdk sdk latest
@j2ghz I assume if you try that on a 2.0.0 sdk it works? It sounds like you are also waiting for this PR to allow GitVersionTask to execute on >= 2.1.0 (simultaneously deprecating support for sdk 1.1.0)
I guess so. I used the fix from the first post, which helped. In the end I turned gitversion off in docker builds, since I get Could not determine assembly version: System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely., even after unshallow. Since it works at Appveyor and Travis, just not at Docker Hub, I think I'll just move the build to one of them.
If it helps - it appears as if the current version of the GitVersion.Tool (5.0.0-beta2-91) ships a version of the libgit2 lib (libgit2-15e1193.so) that depends on OpenSSL 1.0.0, which is not present in microsoft/dotnet:sdk, which is based on Debian Stretch.
This (rather ugly) workaround seems to work, by installing OpenSSL 1.0.0 from Debian Jessie:
Dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk:2.2
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools
COPY jessie.list /etc/apt/sources.list.d/jessie.list
RUN apt-get update -y && \
apt-get install -y libssl1.0.0 && \
apt-get clean -y && \
dotnet tool install --global GitVersion.Tool --version 5.0.0-beta2-91 -v q
jsessie.list:
deb http://httpredir.debian.org/debian jessie main contrib non-free
deb-src http://httpredir.debian.org/debian jessie main contrib non-free
deb http://security.debian.org/ jessie/updates main contrib non-free
deb-src http://security.debian.org/ jessie/updates main contrib non-free
root@7067a21bc27d:~# dotnet gitversion
{
"Major":0,
"Minor":1,
"Patch":0,
"PreReleaseTag":"",
"PreReleaseTagWithDash":"",
"PreReleaseLabel":"",
"PreReleaseNumber":"",
"WeightedPreReleaseNumber":"",
"BuildMetaData":0,
"BuildMetaDataPadded":"0000",
"FullBuildMetaData":"0.Branch.master.Sha.3cbdf2470549030115f933f7993a8b1eab38b40c",
"MajorMinorPatch":"0.1.0",
"SemVer":"0.1.0",
"LegacySemVer":"0.1.0",
"LegacySemVerPadded":"0.1.0",
"AssemblySemVer":"0.1.0.0",
"AssemblySemFileVer":"0.1.0.0",
"FullSemVer":"0.1.0+0",
"InformationalVersion":"0.1.0+0.Branch.master.Sha.3cbdf2470549030115f933f7993a8b1eab38b40c",
"BranchName":"master",
"Sha":"3cbdf2470549030115f933f7993a8b1eab38b40c",
"ShortSha":"3cbdf24",
"NuGetVersionV2":"0.1.0",
"NuGetVersion":"0.1.0",
"NuGetPreReleaseTagV2":"",
"NuGetPreReleaseTag":"",
"VersionSourceSha":"3cbdf2470549030115f933f7993a8b1eab38b40c",
"CommitsSinceVersionSource":0,
"CommitsSinceVersionSourcePadded":"0000",
"CommitDate":"2019-05-14"
}
With the latest version there is no need for the workaround.
You can have a look at the way we ship the docker image with gitversion included https://github.com/GitTools/GitVersion/blob/master/src/Docker/netcoreapp2.1/linux/debian-9/Dockerfile
There is no need to install libgit2-dev and add symlink
As LibGit2Sharp was upgraded to version 0.26 in #1713, I think this problem is fixed. Please reopen this issue if the problem persists.