Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetBuildVersion fails with NullReferenceException when git clone depth is 1 #423

Closed
c80k opened this issue Jan 2, 2020 · 9 comments
Closed

Comments

@c80k
Copy link

c80k commented Jan 2, 2020

For reproduction purpose consider this commit: c80k/capnproto-dotnetcore@5208531
which seems to fix the problem.

Background: The project is built inside an AppVeyor CI. Without the former commit, you'll see something like this in the log:

C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly. [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.Proxy.git_commit_tree_id(ObjectHandle obj) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Commit.<>c__DisplayClass11_0.<.ctor>b__0(ObjectHandle obj) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.GitObjectLazyGroup.<>c__DisplayClass3_0`1.<Singleton>b__0() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at System.Lazy`1.CreateValue() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at System.Lazy`1.LazyInitValue() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at System.Lazy`1.get_Value() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Core.LazyGroup`1.LazyWrapper`1.LibGit2Sharp.Core.ILazy<TType>.get_Value() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at LibGit2Sharp.Commit.get_Tree() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.VersionFile.GetVersion(Commit commit, String repoRelativeProjectDirectory) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.CommitMatchesVersion(Commit commit, SemanticVersion expectedVersion, Position comparisonPrecision, String repoRelativeProjectDirectory) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.<>c__DisplayClass3_0.<GetVersionHeight>b__0(Commit c) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.<>c__DisplayClass30_0.<GetCommitHeight>b__0(Commit p) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at System.Linq.Enumerable.Max(IEnumerable`1 source) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.GetHeight(Commit commit, Func`2 continueStepping) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.GitExtensions.GetVersionHeight(Commit commit, String repoRelativeProjectDirectory, Version baseVersion) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.VersionOracle.CalculateVersionHeight(String relativeRepoProjectDirectory, Commit headCommit, VersionOptions committedVersion, VersionOptions workingVersion) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.VersionOracle..ctor(String projectDirectory, Repository repo, Commit head, ICloudBuild cloudBuild, Nullable`1 overrideVersionHeightOffset, String projectPathRelativeToGitRepoRoot) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.VersionOracle.Create(String projectDirectory, String gitRepoDirectory, ICloudBuild cloudBuild, Nullable`1 overrideBuildNumberOffset, String projectPathRelativeToGitRepoRoot) [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at MSBuildExtensionTask.ContextAwareTask.Execute() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
C:\Users\appveyor\.nuget\packages\nerdbank.gitversioning\3.0.28\build\Nerdbank.GitVersioning.targets(71,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj]
Done Building Project "C:\projects\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj" (Build target(s)) -- FAILED.

The fix just removes the clone_depth property from appveyor.yml.

I understand that cloning the complete repository (i.e. not limiting the clone depth) is essential for calculating the correct version info. My problem was that I totally forgot about the clone depth restriction being set, and that I had a hard time figuring out that this was the actual cause. A meaningful error message instead of letting GetBuildVersion fail unexpectedly would be nice. :-)

@AArnott
Copy link
Collaborator

AArnott commented Jan 2, 2020

Agreed. I'll see what we can do to improve the error message here.

@lbotinelly
Copy link

Just a +1 - experienced a similar issue with actions/checkout@v2 with default parameters. For reference, this was the fix:

      - name: Checkout source
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

@AArnott
Copy link
Collaborator

AArnott commented Mar 13, 2020

Let's see if libgit2sharp can fix it: libgit2/libgit2sharp#1775

jeremymeng added a commit to jeremymeng/ilspy-vscode that referenced this issue Apr 26, 2020
workaround nedbank.gitversion issue dotnet/Nerdbank.GitVersioning#423
danielcirket added a commit to danielcirket/OpenEventSourcing that referenced this issue Jul 6, 2020
* Create build.yml
* Update Nerdbank.GitVersioning for GitHub actions support
* Attempt to work around shallow clone issues with LibGit2Sharp

    See: dotnet/Nerdbank.GitVersioning#423
    See: libgit2/libgit2sharp#1775

* Skip RabbitMQ integration tests when no connection string configured
* Remove dummy service bus connection string to skip Service Bus integration tests
* Skip additional service bus tests when no connection string available
* Skip additional RabbitMQ tests when no connection string is available
* Attempt to get rabbitmq service container working
* Attempt to connect to rabbitmq service container for tests
* Skip rabbitmq management tests if neither connectionstring or management uri configured
* Add service bus connection string secret
* Attempted OS matrix builds for linux and windows builds
* Revert "Attempted OS matrix builds for linux and windows builds"
* Add coverlet flags to dotnet test
* Attempt to store test coverage artifact
* Remove flaky rabbitmq connection finalizer tests
djnicholson added a commit to N3developertoolkit/neo3-visual-tracker that referenced this issue Jul 6, 2020
@wh1t3cAt1k
Copy link

wh1t3cAt1k commented Aug 4, 2020

Just a +1 - experienced a similar issue with actions/checkout@v2 with default parameters. For reference, this was the fix:

      - name: Checkout source
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

Just to note, setting fetch-depth: 0 will fetch the full git history during CI, which, for large repositories, can take quite some time.

If you change your minor version at least sometimes, then setting this to a reasonable restricted value, like 100 or 1000 (depending on your minor versioning frequency), will also work.

@martinussuherman
Copy link

martinussuherman commented Oct 27, 2020

I've experienced different, but related error caused by fetch-depth of 1 (default of actions/checkout@v2), that was fixed by set fetch-depth to 0.

Related build log info:

/home/runner/.nuget/packages/nerdbank.gitversioning/3.3.37/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly.
/home/runner/.nuget/packages/nerdbank.gitversioning/3.3.37/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018: System.InvalidOperationException: Unable to get version from commit: db84405f6054a394ffd6a5e058c93d076760bab0
/home/runner/.nuget/packages/nerdbank.gitversioning/3.3.37/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018:  ---> System.NullReferenceException: Object reference not set to an instance of an object.
/home/runner/.nuget/packages/nerdbank.gitversioning/3.3.37/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018:    at LibGit2Sharp.Core.Handles.ObjectHandle.op_Implicit(ObjectHandle handle)

Full job run info here
Hope this help anyone else stumbling into this particular problem.

@AArnott
Copy link
Collaborator

AArnott commented Nov 24, 2020

Duplicate of #92

@AArnott AArnott marked this as a duplicate of #92 Nov 24, 2020
@AArnott AArnott closed this as completed Nov 24, 2020
warrenbuckley pushed a commit to umbraco/Umbraco.BlockGrid.Example.Website that referenced this issue Nov 28, 2022
@NightOwl888
Copy link

NightOwl888 commented Feb 5, 2023

Looks like Azure DevOps changed the default settings to use shallow fetch = 1.

Important

New pipelines created after the September 2022 Azure DevOps sprint 209 update have Shallow fetch enabled by default and configured with a depth of 1. Previously the default was not to shallow fetch. To check your pipeline, view the Shallow fetch setting in the pipeline settings UI.

This breaks new pipelines that use ngvb that don't set the fetch depth explicitly. https://dev.to/kkazala/azure-devops-pipelines-shallow-fetch-1-is-now-default-4656 has the solution for YAML:

steps:
  - checkout: self
    fetchDepth: 0

According to the docs, the YAML config is supposed to take precedence over the UI setting.

@Mike-E-angelo
Copy link

In my case, I have a submodule that appears to be breaking a new Azure Pipeline that I created today. I have fetchDepth: 0 applied, but it still fails on a submodule hash. I have not seen anything in my searching and would appreciate any pointers.

@Mike-E-angelo
Copy link

OK I got it working! I believe this had to do with a bad .gitmodules in my SLN pointing to a branch that no longer exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants