You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps中设置InformationalVersion为何自动追加SHA哈希?

解决Azure DevOps管道版本号追加问题

1. 修复Version字段无法添加构建号的语法错误

你之前的Version参数写法有误,缺少了等号,正确格式应为:

/p:Version=$(versionNumber)+$(Build.BuildNumber)

修正后就能把构建号以SemVer元数据格式追加到Version字段中。

2. 禁用InformationalVersion自动追加提交SHA

.NET SDK默认会在InformationalVersion末尾自动添加源代码提交哈希,要关闭这个行为,只需在构建命令中添加/p:IncludeSourceRevisionInInformationalVersion=false参数。

完整构建命令示例

结合以上两个修复,最终的构建命令如下:

--configuration Release --output $(Build.ArtifactStagingDirectory) --self-contained true --runtime win-x64 /p:Version=$(versionNumber)+$(Build.BuildNumber) /p:InformationalVersion=$(versionNumber)+$(Build.BuildNumber) /p:IncludeSourceRevisionInInformationalVersion=false

额外说明

  • 上述配置适用于SDK风格项目(.NET Core/.NET 5及以上版本),这类项目默认支持通过MSBuild属性控制版本信息。
  • 如果是旧版.NET Framework项目,需要确保项目文件中已显式声明Version和InformationalVersion属性,才能通过MSBuild参数覆盖。

内容的提问来源于stack exchange,提问作者Schoof

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 03:42:08