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
相关产品推荐
相关产品推荐

