自定义版本后缀MinVer

Customize version suffix MinVer

我正在使用 MinVer,但找不到如何获取提交高度来创建自定义版本后缀。理想情况下,我想要 1.0.0-preview.{commits} 而不是 1.0.0.-preview.0.{commits}。预发布标签和提交高度之间的零是多少我不知道。 (是的,我已将 <MinVerDefaultPreReleasePhase> 设置为预览 :))

其次,使用GitInfo I notice a discrepancy in the number of commits. Below is output from some me experimenting on github

$ dotnet Application.dll
========== Git ==========
Commit     a54e9e9
Commit SHA a54e9e96868470ebf13d4a35ce9858c09a534363
Branch     remotes/origin/master
Tag
Commits    39
========== Assembly ==========
Version              1.0.0
Assembly             Not found: AssemblyVersionAttribute
Informational        1.0.0-preview.0.34+a54e9e96868470ebf13d4a35ce9858c09a534363
File                 1.0.0.24 // AzDo BuildId=24

诊断 MinVer 给了我一些关于根提交的提示,但我对 git 决定根提交的因素知之甚少。

MinVer: Starting at commit a54e9e9 (height 0)...
  MinVer: History diverges from 3c0633f (height 20) to:
  MinVer: - 56af0a5 (height 21)
  MinVer: - 747ef5a (height 21)
  MinVer: Following path from 3c0633f (height 20) through first parent 56af0a5 (height 21)...
  MinVer: Found root commit { Commit: faa505b, Tag: null, Version: 0.0.0-preview.0, Height: 34 }.
  MinVer: Backtracking to 3c0633f (height 20) and following path through last parent 747ef5a (height 21)...
  MinVer: History converges from 0f35453 (height 24) back to previously seen commit 8dc52dc (height 25). Abandoning path.
  MinVer: 39 commits checked.
  MinVer: No commit found with a valid SemVer 2.0 version prefixed with ''. Using default version 0.0.0-preview.0.
  MinVer: Using { Commit: faa505b, Tag: null, Version: 0.0.0-preview.0, Height: 34 }.

所以,总结一下:

  1. 如何为 MinVer 自定义版本后缀?
  2. 零 {MinVerDefaultPreReleasePhase}.0.{commits} 代表什么?
  3. 提交高度如何calculated/determined?

第三个问题让我进入 versioning of NuGet 和有关 FileVersionAssembly 的部分,特别是版本号的修订部分。但我把这个留给另一个问题。

注意 我尝试添加标签 minver 但由于信誉不佳无法添加:)

谢谢

乔金

  1. How do I customize version suffix for MinVer?

我假设“版本后缀”指的是pre-release identifiers。您不能自定义所有这些,只能自定义默认的预发布阶段,您已经使用 MinVerDefaultPreReleasePhase.


  1. What does the zero {MinVerDefaultPreReleasePhase}.0.{commits} represent?

这是一个标记值,代表下一个版本发布之前的中间版本。请记住,MinVer 中的一个基本假设是您在发布前标记,因此您永远不会发布这些版本之一。例如。当前提交可能正在构建 0.0.0-preview.0.34。当你想发布你的第一个预览版时,你会用 1.0.0-preview.1 标记提交,MinVer 会将该版本嵌入到你的程序集和包中。


  1. How is the commit height calculated/determined?

这在"How it works"中有解释:

You will notice that MinVer adds another number to the pre-release identifiers when the current commit is not tagged. This is the number of commits since the latest tag, or if no tag was found, since the root commit. This is known as "height". For example, if the latest tag found is 1.0.0-beta.1, at a height of 42 commits, the calculated version is 1.0.0-beta.1.42.

并且来自 FAQ

What if the history diverges, and then converges again, before the latest tag (or root commit) is found?

MinVer will use the height on the first path followed where the history diverges. The paths are followed in the same order that the parents of the commit are stored in git. The first parent is the commit on the branch that was the current branch when the merge was performed. The remaining parents are stored in the order that their branches were specified in the merge command.

您还可以看到,非常详细,how MinVer walks the history:

Can I get log output to see how MinVer calculates the version?

Yes! MinVerVerbosity can be set to quiet, minimal (default), normal, detailed, or diagnostic.

At the diagnostic level you will see how MinVer walks the commit history, in excruciating detail.