In my repository, I am using NBGV. However, in a PR merged some 16 hours ago, due to a mistake on my part, I committed version.json with a missing comma after an array item. I have corrected this oversight in a later commit. However, every time I attempt to do a release build, I get the following error:
The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly.
System.InvalidOperationException: Unable to get version from commit: c2d63655bafc523d14f77cea0af9b8f42e0f72ec ---> Newtonsoft.Json.JsonReaderException: After parsing a value an unexpected character was encountered: ". Path 'publicReleaseRefSpec[0]', line 6, position 4.
at Newtonsoft.Json.JsonTextReader.ParsePostValue(Boolean ignoreComments)
at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)
at Newtonsoft.Json.JsonTextReader.ReadAsString()
at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Nerdbank.GitVersioning.VersionFile.TryReadVersionJsonContent(String jsonContent, String repoRelativeBaseDirectory)
at Nerdbank.GitVersioning.VersionFile.GetVersion(Commit commit, String repoRelativeProjectDirectory)
at Nerdbank.GitVersioning.GitExtensions.GitWalkTracker.GetVersion(Commit commit)
--- End of inner exception stack trace ---
at Nerdbank.GitVersioning.GitExtensions.GitWalkTracker.GetVersion(Commit commit)
at Nerdbank.GitVersioning.GitExtensions.CommitMatchesVersion(Commit commit, SemanticVersion expectedVersion, Position comparisonPrecision, GitWalkTracker tracker)
at Nerdbank.GitVersioning.GitExtensions.<>c__DisplayClass3_0.<GetVersionHeight>b__0(Commit c)
at Nerdbank.GitVersioning.GitExtensions.<GetCommitHeight>g__TryCalculateHeight|34_0(Commit commit, <>c__DisplayClass34_0& )
at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit startingCommit, GitWalkTracker tracker, Func`2 continueStepping)
at Nerdbank.GitVersioning.GitExtensions.GetHeight(Commit commit, String repoRelativeProjectDirectory, Func`2 continueStepping)
at Nerdbank.GitVersioning.GitExtensions.GetVersionHeight(Commit commit, String repoRelativeProjectDirectory, Version baseVersion)
at Nerdbank.GitVersioning.VersionOracle.CalculateVersionHeight(String relativeRepoProjectDirectory, Commit headCommit, VersionOptions committedVersion, VersionOptions workingVersion)
at Nerdbank.GitVersioning.VersionOracle..ctor(String projectDirectory, Repository repo, Commit head, ICloudBuild cloudBuild, Nullable`1 overrideVersionHeightOffset, String projectPathRelativeToGitRepoRoot)
at Nerdbank.GitVersioning.VersionOracle.Create(String projectDirectory, String gitRepoDirectory, ICloudBuild cloudBuild, Nullable`1 overrideBuildNumberOffset, String projectPathRelativeToGitRepoRoot)
at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner()
at MSBuildExtensionTask.ContextAwareTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() MSIExtract.AppxPackage C:\Users\William\.nuget\packages\nerdbank.gitversioning\3.2.31\build\Nerdbank.GitVersioning.targets 72
It is still choking on the invalid JSON from that PR many commits ago. How would I resolve this? Note that the broken commit is in there for good; I cannot simply excise it from the history. Thanks for your help!
Hi @wjk. Since nb.gv by design walks history, it's not enough to 'fix' the change in a follow-up commit. Ideally, you fix it before ever pushing and merging your commits. But since that's all behind us now...
The fix for you is the same as described in this doc. Namely: commit a _removal_ of the defective file, then commit a reintroduction of the (corrected) file. Then push those commits directly to your broken branch. Do _not_ squash and do _not_ merge. It must be a 'fast forward' push of your two new commits onto your broken branch. This way, nb.gv will encounter a commit with no version.json file at all, and stop there instead of walking further down history to find your defective ones.
Most helpful comment
Hi @wjk. Since nb.gv by design walks history, it's not enough to 'fix' the change in a follow-up commit. Ideally, you fix it before ever pushing and merging your commits. But since that's all behind us now...
The fix for you is the same as described in this doc. Namely: commit a _removal_ of the defective file, then commit a reintroduction of the (corrected) file. Then push those commits directly to your broken branch. Do _not_ squash and do _not_ merge. It must be a 'fast forward' push of your two new commits onto your broken branch. This way, nb.gv will encounter a commit with no version.json file at all, and stop there instead of walking further down history to find your defective ones.