You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Dealing with legacy version.txt or version.json files
4
+
5
+
When you already have a version.txt or version.json file in your repo and want to use Nerdbank.GitVersioning,
6
+
you may find that your build breaks when NB.GV tries to parse your version.txt or version.json file(s).
7
+
8
+
Any such version.txt or version.json files in project directories with NB.GV installed, or any parent directory up to the repo root, must be removed in a commit *prior* to the commit that defines the new NB.GV-compliant version.json file. This will ensure that NB.GV will not discover the legacy files and try to parse them.
9
+
10
+
It is important that you maintain that clean break where no commit with a NB.GV version.json file has an immediate parent commit with a legacy version file. A merge commit (like a pull request with your migration changes would create) will defeat your work by having the new version.json file and an immediate parent with the version.txt file (the one from your base branch). It is therefore mandatory that if you have such a legacy file, that when you're done validating the migration that you *directly push your 2+ commits to your branch* rather than complete a pull request. If your team's policy is to use pull requests, you can create one for review, but complete it by pushing the commits directly rather than letting the git service create the merge commit for you by completing the pull request. If the push is rejected because it is not a fast-forward merge, *rebase* your changes since a local merge commit would similarly defeat your efforts.
11
+
12
+
Also note that any other open pull requests that are based on a commit from before your changes may also introduce the problematic merge commit by providing a direct parent commit path from the new version.json file to the legacy one. These open PRs must be squashed when completed or rebased.
13
+
14
+
## Maintaining an incrementing version number
15
+
16
+
When defining your new [version.json file](versionJson.md), you should set the version to be same *major.minor* version that you used before or higher.
17
+
If you are matching the prior *major.minor* version and need the build height integer (usually the 3rd integer) of your version to start higher than the last version from your legacy mechanism, set the `"buildNumberOffset"` field in the version.json file to be equal to or greater than the 3rd integer in the old version. Note that the first build height will be *one more than* the number you set here, since the commit with your changes adds to the offset you specify.
18
+
19
+
For example, suppose your last release was of version 1.2.4. When you switch to NB.GV, you may use a `version.json` file with this content:
20
+
21
+
```json
22
+
{
23
+
"version": "1.2",
24
+
"buildNumberOffset": 4
25
+
}
26
+
```
27
+
28
+
After commiting this change, the first version NB.GV will assign to your build is `1.2.5`.
29
+
30
+
When you later want to ship v1.3, remove the second field so that the 3rd integer resets:
31
+
32
+
```json
33
+
{
34
+
"version": "1.3"
35
+
}
36
+
```
37
+
38
+
This will make your first 1.3 build be versioned as 1.3.1.
You must also create [a version.json file](doc/versionJson.md) in your repo.
31
+
You must also create [a version.json file](doc/versionJson.md) in your repo. See [migration notes](doc/migrating.md) if your repo already has a version.txt or version.json file from using another system.
32
32
33
33
## How to leverage version stamping and runtime information
34
34
@@ -59,7 +59,7 @@ the git 'height' of the version, and the git commit ID.
59
59
### Version generation
60
60
61
61
Given the same settings as used in the discussion above, a NuGet or NPM package may be
62
-
assigned this version:
62
+
assigned this version:
63
63
64
64
1.0.24-alpha-g9a7eb6c819
65
65
@@ -86,7 +86,7 @@ The git commit ID does not represent an alphanumerically sortable identifier
86
86
in semver, and thus delivers a poor package update experience for NuGet package
87
87
consumers. Incrementing the PATCH with each public release ensures that users
88
88
who want to update to your latest NuGet package will reliably get the latest
89
-
version.
89
+
version.
90
90
91
91
The git height is guaranteed to always increase with each release within a given major.minor version,
92
92
assuming that each release builds on a previous release. And the height automatically resets when
@@ -98,14 +98,14 @@ It could be, but the git height serves as a pseudo-identifier already and the
98
98
git commit id would just make it harder for users to type in the version
99
99
number if they ever had to.
100
100
101
-
Note that the git commit ID is *always* included in the
101
+
Note that the git commit ID is *always* included in the
102
102
`AssemblyInformationVersionAttribute` so one can always match a binary to the
103
103
exact version of source code that produced it.
104
104
105
105
### How do I translate from a version to a git commit and vice versa?
106
106
107
107
A pair of Powershell scripts are included in the Nerdbank.GitVersioning NuGet package
108
-
that can help you to translate between the two representations.
108
+
that can help you to translate between the two representations.
0 commit comments