Not working in .NET Core docker image
See original GitHub issueHello!
Just added NerdBank.GitVersioning to a .NET Core solution, and I’m receiving some errors.
The solution is build with GitLab CI on a Docker container running the image microsoft/dotnet:2.1-sdk
.
The error I’m getting when building:
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly. [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load shared library '/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/lib/linux/x86_64/libgit2-6311e88.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libssl.so.1.0.0: cannot open shared object file: No such file or directory [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: at System.Runtime.Loader.AssemblyLoadContext.InternalLoadUnmanagedDllFromPath(String unmanagedDllPath) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: at System.Runtime.Loader.AssemblyLoadContext.LoadUnmanagedDllFromPath(String unmanagedDllPath) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: at MSBuildExtensionTask.ContextAwareTask.CustomAssemblyLoader.LoadUnmanagedDll(String unmanagedDllName) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: at System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll(String unmanagedDllName, IntPtr gchManagedAssemblyLoadContext) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: at LibGit2Sharp.Core.NativeMethods.git_libgit2_init() [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: at LibGit2Sharp.Core.NativeMethods.LoadNativeLibrary() [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: at LibGit2Sharp.Core.NativeMethods..cctor() [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: --- End of inner exception stack trace --- [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: at LibGit2Sharp.Core.NativeMethods.git_libgit2_opts(Int32 option, UInt32 level, String path) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: at LibGit2Sharp.GlobalSettings.SetConfigSearchPaths(ConfigurationLevel level, String[] paths) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: at Nerdbank.GitVersioning.GitExtensions.OpenGitRepo(String pathUnderGitRepo) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: at Nerdbank.GitVersioning.VersionOracle.Create(String projectDirectory, String gitRepoDirectory, ICloudBuild cloudBuild, Nullable`1 overrideBuildNumberOffset, String projectPathRelativeToGitRepoRoot) [/build/nerdbank.csproj]
/root/.nuget/packages/nerdbank.gitversioning/2.2.33/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner() [/build/nerdbank.csproj]
After digging around for a couple of hours, I tried to create a new console project inside the container and then adding NerdBank.GitVersioning:
Running in Docker docker run --rm -it microsoft/dotnet:2.1-sdk bash
apt-get update -y && apt-get upgrade -y
export PATH="$PATH:/root/.dotnet/tools"
dotnet tool install -g nbgv
git init
dotnet new console
nbgv install
And then I got the following error:
Unhandled Exception: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'git2-6311e88' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libgit2-6311e88: cannot open shared object file: No such file or directory
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_libgit2_opts(Int32 option, UInt32 level, String path)
at LibGit2Sharp.GlobalSettings.SetConfigSearchPaths(ConfigurationLevel level, String[] paths)
at Nerdbank.GitVersioning.GitExtensions.OpenGitRepo(String pathUnderGitRepo)
at Nerdbank.GitVersioning.Tool.Program.OnInstallCommand(String versionJsonRoot, String version) in D:\a\1\s\src\nbgv\Program.cs:line 151
at Nerdbank.GitVersioning.Tool.Program.Main(String[] args) in D:\a\1\s\src\nbgv\Program.cs:line 100
I’ve googled a bit and found some issues similar to mine, but the workarounds or solutions provided didn’t work.
Am I doing anything wrong? Can someone point in the right direction?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
Why isn't my ASP.NET Core app in Docker working?
In this post I describe a problem where my ASP.NET Core ... NET Core supports CentOS, they don't provide Docker images with it...
Read more >ASP.NET Core Docker Container App not accessible
Basically, in the asp.net core code, it only listens to localhost which is in Container, but not your local pc. You can solve...
Read more >NET Core Docker Container Not Working in Kubernetes
NET Core Docker container that isn't working in Kubernetes can be a complex task, but with a systematic approach, you can identify and...
Read more >Troubleshooting an ASP.NET Core App Running in Docker
This involves running the Docker container on the build server, and checking that the container starts up correctly.
Read more >Docker images for ASP.NET Core
Learn how to use the published ASP.NET Core Docker images from the Docker Registry. Pull and build your own images.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve tried with almost all releases from 2.1.x and I couldn’t get it to work. I’ll wait for a new version from libgit2.
As for why I must use Debian… it’s not a case of must, more a case of not wanting to change right now; I have a reasonable number of applications running in my CI pipeline generating images and this change from Debian to Ubuntu would have to be properly validated, and right now it wouldn’t be a good time.
I’ll close this one (if it’s OK with you), and will try again when you release a new version 😄
Yes, I have. I haven’t looked into it deeply, because my first take suggests it would be incredibly slow. We have to look for version.json files in the tree for each commit in history till we find certain significant changes. That would mean a lot of git.exe invocations. libgit2sharp is much faster than git.exe. Since this runs in people’s builds, and can run many times in a build because it may run once for each project, perf is a very high priority.