[Bug] GitVersion is crashing when trying to update AssemblyInfo.cs files.
See original GitHub issueDescribe the bug
Command used in Windows 10 command prompt or PowerShell as well as Azure DevOps build pipeline:
gitversion /updateassemblyinfo
GitVersion is crashing when trying to update AssemblyInfo.cs files.
Expected Behavior
I expected the version in the GitVersion.yml file to be applied to the AssemblyInfo.cs files since it is higher than the latest tag.
Actual Behavior
INFO [02/24/21 12:02:31:25] Working directory: C:\git\Upmc.ServiceBus.Common.V3
INFO [02/24/21 12:02:31:29] Project root is: C:\git\Upmc.ServiceBus.Common.V3\
INFO [02/24/21 12:02:31:29] DotGit directory is: C:\git\Upmc.ServiceBus.Common.V3\.git
INFO [02/24/21 12:02:31:34] Begin: Loading version variables from disk cache
INFO [02/24/21 12:02:31:34] Begin: Deserializing version variables from cache file C:\git\Upmc.ServiceBus.Common.V3\.git\gitversion_cache\C39A271AF962B211C0A0EB6135B5B939FBB199F0.yml
WARN [02/24/21 12:02:31:40] Unable to read cache file C:\git\Upmc.ServiceBus.Common.V3\.git\gitversion_cache\C39A271AF962B211C0A0EB6135B5B939FBB199F0.yml, deleting it.
INFO [02/24/21 12:02:31:41] System.InvalidOperationException: Sequence contains no matching element
at GitVersion.OutputVariables.VersionVariables.FromFile(String filePath, IFileSystem fileSystem, ILog log)
at GitVersion.VersionCalculation.Cache.GitVersionCache.LoadVersionVariablesFromDiskCache(GitVersionCacheKey key)
INFO [02/24/21 12:02:31:41] End: Deserializing version variables from cache file C:\git\Upmc.ServiceBus.Common.V3\.git\gitversion_cache\C39A271AF962B211C0A0EB6135B5B939FBB199F0.yml (Took: 72.49ms)
INFO [02/24/21 12:02:31:41] End: Loading version variables from disk cache (Took: 73.39ms)
INFO [02/24/21 12:02:31:45] Using latest commit on specified branch
INFO [02/24/21 12:02:31:46] Begin: Attempting to inherit branch configuration from parent branch
INFO [02/24/21 12:02:31:47] Begin: Finding branch source of 'feature/UpdateEventConvention'
INFO [02/24/21 12:02:31:48] Begin: Finding merge base between 'feature/UpdateEventConvention' and 'develop'.
INFO [02/24/21 12:02:31:49] Found merge base of e50099d Merged PR 40222: refactored multi-client code
INFO [02/24/21 12:02:31:49] Merge base of feature/UpdateEventConvention' and 'develop is e50099d Merged PR 40222: refactored multi-client code
INFO [02/24/21 12:02:31:49] End: Finding merge base between 'feature/UpdateEventConvention' and 'develop'. (Took: 12.31ms)
INFO [02/24/21 12:02:31:49] Begin: Finding merge base between 'feature/UpdateEventConvention' and 'master'.
INFO [02/24/21 12:02:31:50] End: Finding merge base between 'feature/UpdateEventConvention' and 'master'. (Took: 4.28ms)
INFO [02/24/21 12:02:31:50] End: Finding branch source of 'feature/UpdateEventConvention' (Took: 27.41ms)
INFO [02/24/21 12:02:31:50] End: Attempting to inherit branch configuration from parent branch (Took: 41.27ms)
ERROR [02/24/21 12:02:31:50] An unexpected error occurred:
System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)
---> System.NullReferenceException: Object reference not set to an instance of an object.
at GitVersion.GitObject..ctor(GitObject innerGitObject)
at GitVersion.Commit..ctor(Commit innerCommit)
at GitVersion.GitRepository.<>c__DisplayClass27_0.<FindMergeBase>b__0()
at GitVersion.Helpers.OperationWithExponentialBackoff`2.ExecuteAsync()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at GitVersion.GitRepository.FindMergeBase(ICommit commit, ICommit otherCommit)
at GitVersion.RepositoryStore.FindMergeBase(IBranch branch, IBranch otherBranch)
at GitVersion.RepositoryStore.<>c__DisplayClass29_0.<GetMergeCommitsForBranch>b__2(IBranch otherBranch)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
at System.Linq.OrderedEnumerable`1.ToList()
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at GitVersion.RepositoryStore.GetMergeCommitsForBranch(IBranch branch, Config configuration, IEnumerable`1 excludedBranches)
at GitVersion.RepositoryStore.FindCommitBranchWasBranchedFrom(IBranch branch, Config configuration, IBranch[] excludedBranches)
at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches)
at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches)
at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions)
at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__3()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at System.Lazy`1.get_Value()
at GitVersion.VersionCalculation.NextVersionCalculator.get_context()
at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion()
at GitVersion.GitVersionCalculateTool.CalculateVersionVariables()
at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions)
INFO [02/24/21 12:02:31:50] Attempting to show the current git graph (please include in issue):
INFO [02/24/21 12:02:31:50] Showing max of 100 commits
INFO [02/24/21 12:02:31:64] * d6747b0 4 hours ago (HEAD -> feature/UpdateEventConvention, origin/feature/UpdateEventConvention)
* e50099d 3 months ago (origin/develop, origin/HEAD, develop)
|\
| * 6f79c31 3 months ago
| * d7d38cc 3 months ago
| * 8afc799 3 months ago
| * 4694b49 3 months ago
| * 456f16b 3 months ago
| * aaf1cda 3 months ago
|/
* 57a1600 3 months ago
|\
| * 46fe446 3 months ago
| * 43eccb0 3 months ago
|/
* dceedd3 3 months ago
|\
| * 68e98d5 3 months ago
| * a498213 3 months ago
| * 6ea2b1c 3 months ago
|/
* 82b1a08 3 months ago
|\
| * b73ff5b 3 months ago
| * a95447f 3 months ago
| * 9354355 3 months ago
| * bd08f2a 3 months ago
| * 3c14cf6 3 months ago
|/
* 7283a86 3 months ago
|\
| * 69a5031 3 months ago
| * d50b889 3 months ago
| * 977f94c 3 months ago
|/
* a2641e5 4 months ago
* 1855878 4 months ago
* 402dc3a 4 months ago
|\
| * 577636d 4 months ago
|/
* 0b317e6 5 months ago
|\
| * 5ac0df6 5 months ago
| * b67e852 5 months ago
| |\
| |/
|/|
* | efb2e3d 5 months ago
|\ \
| | * bc0ada2 5 months ago
| |/
| * 8eeb6ea 5 months ago
|/
* 702e36b 7 months ago
|\
| * fc1ef01 7 months ago
|/
* 89522b9 11 months ago
|\
| * 8855b5e 11 months ago
| * ed1858e 11 months ago
|/
* df60e40 12 months ago
|\
| * 25be4e5 12 months ago
* | 0e243cc 12 months ago
|\|
| * 48a16b8 12 months ago
|/
* 71ce83b 12 months ago
|\
| * c66cc94 12 months ago
* | feeaf17 12 months ago
|\|
| * 40b0f17 12 months ago
| * 3b7d149 12 months ago
| * 55b655b 12 months ago
| * e849bf7 12 months ago
|/
* b70bc0a 12 months ago
|\
| * 4deb182 12 months ago
| * 23d1ea7 12 months ago
| * 1625e5b 12 months ago
| * 36aeb2c 12 months ago
| * b6c1050 12 months ago
| * 0dbaaba 12 months ago
| * 9372f85 12 months ago
| * f3bdb09 12 months ago
| * 72b5e78 12 months ago
| * cad4f4d 12 months ago
| * f99323a 12 months ago
| * 45f3d8d 12 months ago
| * dd1c115 12 months ago
|/
* 5409029 1 year ago
|\
| * a4a01a9 1 year ago
|/
* 63c548d 1 year, 1 month ago
| * bb73ddf 12 months ago (origin/master, master)
| * 132ae1b 1 year, 1 month ago (tag: 2.3.1)
| * f41353f 1 year, 2 months ago (tag: 2.3.0)
| |\
| | * f268a2e 1 year, 2 months ago
| |/
|/|
* | f4a6310 1 year, 2 months ago
|\ \
| * | 8d7e1a4 1 year, 2 months ago
| * | e137d84 1 year, 2 months ago
|/ /
* | f04e6fe 1 year, 3 months ago
|\ \
| * | d377257 1 year, 3 months ago
|/| |
| * | 6cd047f 1 year, 3 months ago
| * | a93c885 1 year, 3 months ago
|/ /
* | 4a75a59 1 year, 4 months ago
|\ \
| * | 1b8d455 1 year, 4 months ago
| * | cb174f9 1 year, 4 months ago
|/ /
* | f033008 1 year, 4 months ago
|\ \
| * | 60ea065 1 year, 4 months ago
| * | 7872bdc 1 year, 4 months ago
| |\ \
| |/ /
|/| |
* | | f515d22 1 year, 5 months ago
|\ \ \
| * \ \ 3caad66 1 year, 5 months ago
| |\ \ \
| |/ / /
|/| | |
| * | | 5a2365c 1 year, 5 months ago
| | * | 29f2400 1 year, 4 months ago
| |/ /
|/| |
* | | a8f1ede 1 year, 5 months ago
|\ \ \
| |/ /
|/| |
| * | 74f7c7b 1 year, 5 months ago
| * | b1616ad 1 year, 5 months ago
|/ /
| * 26b501d 1 year, 6 months ago (tag: 2.1.1)
| |\
| |/
|/|
* | a929ff5 1 year, 6 months ago
* | cc79df1 1 year, 6 months ago
* | 9c3a568 1 year, 6 months ago
* | 362e029 1 year, 7 months ago
|\ \
| * | 12fd747 1 year, 7 months ago
|/ /
| * 87c7bfd 1 year, 7 months ago (tag: 2.0.5)
| |\
| | * 3c64ed5 1 year, 7 months ago
| |/
|/|
[GitVersion.yml.txt](https://github.com/GitTools/GitVersion/files/6038051/GitVersion.yml.txt)
Possible Fix
Steps to Reproduce
I am not able to share the source code from our internal Git source repository because of intellectual property.
Context
We use GitVersion as part of our Azure DevOps build pipelines to assign the assembly version information at build time.
Your Environment
Azure DevOps (hosted) Classic Build Pipeline
- Version Used: 5.6.6+Branch.main.Sha.80adc3f3b8919b655adca7b796b273fb10478c3f
- Operating System and version (Windows 10 and Azure DevOps):
- Link to your project: (Private)
- Link to your CI build (if appropriate): (Private)
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Using GitVersion for AssemblyInfo.cs update
cs files in the git repo and update them. It will update the following assembly attributes: AssemblyVersion will be set to the AssemblySemVer ......
Read more >Assembly Patching
GitVersion.exe /updateassemblyinfo will recursively search for all AssemblyInfo.cs or AssemblyInfo.vb files in the git repo and update them.
Read more >GitVersion Adding Duplicate 'AssemblyFileVersion' ...
As a workaround we have unticked update AssemblyInfo on gitversion. Has something changed on the hosted agents VS2017 GitVersion? Same issue ...
Read more >GitTools/GitVersion 5.10.0 on GitHub
#2605 [Bug] GitVersion is crashing when trying to update AssemblyInfo.cs files. #2631 [Bug] GitVersion.MsBuild 5.6.7 The command ""C:\Users\UserName.nuget\ ...
Read more >Access Git Information from MSBuild and Code
Logging code inside your app/library could also trace this information, so that error logs or crash reports could include this information too, ...
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 came across this issue as well, but on a different set of steps. I was experimenting with ways to limit git history to a particular folder by running git branch-filter command. Running GitVersion on the filtered repository worked with 5.5.0, but failed with 5.6.6, at the same place @robbrattonUPMC reported.
It is possible for a branch to have a different history than that of its parent branch, orphan branches for example.
Here is a simple powershell script that reproduces the problem.
I’m happy to fix and write tests for this issue, if this is identified as a bug, or as an improvement.
I was running into the same issue and discovered that it happened if any of the branches in the repository had no commits. In my case it was the Master branch, which was not initialized with a ReadMe.md. I noticed it because it failed on a pull request right where it was trying to find the merge base between the feature and master branch. So, my question is, how can I get the GitVersion.exe /updateassemblyinfo to only consider the branches relevant to the merge when determining the merge base, and to ignore all other branches?