我从 here 获取全局配置后,我的 GitVersion.yml 如下所示
但问题是,当我运行 gitversion 时,这会引发异常
无法格式化 AssemblyInformationalVersion。检查您的格式字符串:“InformationalVersion”不是“GitVersion.SemanticVersionFormatValues”类型的成员(参数“propertyOrFieldName”)
我必须删除第五行
程序集信息格式:“{InformationalVersion}”
使异常消失。
我尝试了以下方法,但没有成功。
程序集信息格式:{InformationalVersion} # 删除了引号。
我错过了什么。
next-version: 0.1.0
mode: mainline
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatchTag
assembly-informational-format: '{InformationalVersion}'
increment: Inherit
continuous-delivery-fallback-tag: ci
tag-prefix: '[vV]'
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
no-bump-message: '\+semver:\s?(none|skip)'
legacy-semver-padding: 4
build-metadata-padding: 4
commits-since-version-source-padding: 4
commit-message-incrementing: Enabled
commit-date-format: 'yyyy-MM-dd'
branches:
master:
mode: ContinuousDelivery
tag: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^master
tracks-release-branches: false
is-release-branch: false
release:
mode: ContinuousDelivery
tag: beta
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^releases?[/-]
tracks-release-branches: false
is-release-branch: true
pre-release-weight: 1000
feature:
mode: ContinuousDeployment
tag: useBranchName
increment: Inherit
prevent-increment-of-merged-branch-version: false
track-merge-target: false
regex: ^features?[/-]
tracks-release-branches: false
is-release-branch: false
pull-request:
mode: ContinuousDelivery
tag: PullRequest
increment: Inherit
prevent-increment-of-merged-branch-version: false
tag-number-pattern: '[/-](?<number>\d+)[-/]'
track-merge-target: false
regex: ^(pull|pull\-requests|pr)[/-]
tracks-release-branches: false
is-release-branch: false
hotfix:
mode: ContinuousDelivery
tag: beta
increment: Patch
prevent-increment-of-merged-branch-version: false
track-merge-target: false
regex: ^hotfix(es)?[/-]
tracks-release-branches: false
is-release-branch: false
support:
mode: ContinuousDelivery
tag: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^support[/-]
tracks-release-branches: false
is-release-branch: false
develop:
mode: ContinuousDeployment
tag: unstable
increment: Minor
prevent-increment-of-merged-branch-version: false
track-merge-target: true
regex: ^dev(elop)?(ment)?$
tracks-release-branches: true
is-release-branch: false
ignore:
sha: []
merge-message-formats: {}
最佳答案
因此,InformationalVersion
是根据 assembly-informational-format
指定的格式设置的。所以这可能是导致错误的原因。
例如,我所做的事情是这样的:
assembly-informational-format: '{MajorMinorPatch}{PreReleaseTagWithDash}+{ShortSha}'
然后,当我运行 GitVersion 时,我得到:
"InformationalVersion":"2.0.0-convert-to-netcore.9+abc123"
同样,文档并不清楚哪些变量可以用作字符串插值的一部分,以及哪些变量由各种格式字段设置。
更新
我注意到我的回答似乎与 GitVersion 的文档相矛盾。然而,我的经验向我证明,设置assemble-informational-format
会影响InformationalVersion
的值,即使InformationalVersion
被认为是一个变量并且可以用于插值。我认为这可能是 GitVersion 文档中的一个错误。或者最多,该 InformationalVersion
可以用作其他格式的变量,但因为 assemble-informational-format
决定了 InformationalVersion
的最终值code>,此变量不能在 assemble-informational-format
配置值中使用。
另一个更新
好吧,我意识到,虽然文档可以做得更好,但我一直对 GitVersion 实际在做什么/提供什么有误解。这不是魔法(嗯,有点像;)),它确实需要您的努力。
GitVersion 只是计算 SemVer 的一些版本字段,并在运行 GitVersion.exe
时(使用可执行文件时)将这些计算结果输出到 JSON 对象中。 GitVersion 还提供了这些字段的一些常见的“混搭”,例如MajorMinor
、MajorMinorPatch
等。它还为您提供了一些格式化完整版本号的方法,例如程序集文件版本控制格式
和程序集信息格式
。但最终,所有这些的结果都输出到一个 JSON 对象。
您有责任从此 JSON 对象中挑选和选择如何构建您的版本号。因此,如果您想使用 InformationalVersion
中的字符串作为 NuGet 包版本(对于 v3 包源),该版本基于 assemble-informational-format
中指定的格式,这是你的选择。
GitVersion 提供了有关如何将此 JSON 对象“转换”为可从构建过程访问的构建变量或环境变量的说明。 您需要确保配置您的构建以使用这些值来实现您想要的版本控制方案。但 GitVersion 只计算主要/次要/补丁版本号,并尝试帮助您格式化预发布和构建元数据标签。
这个启示确实帮助我更好地理解了如何配置 GitVersion 并在我的构建过程中使用它。
关于gitversion - GitVersion.yml 中的 assembly-informational-format 应该设置为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59919614/