使用 Core 和 DevOps 管道自动递增构建
AutoIncrementing Build with Core and DevOps Pipeline
我正在尝试为使用 Azure Pipelines 构建的 ASP.NET Core 3.1 Web 应用程序设置一个自动递增的版本号。我已经尝试了各种片段和管道任务,并尽可能生成版本号,但我的构建失败并显示消息
指定的版本字符串不符合要求的格式 - major[.minor[.build[.revision]
我正在使用以下 yml 片段生成版本号:
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
version.MajorMinor: '1' # Manually adjust the version number as needed for semantic versioning. Revision is auto-incremented.
version.Revision: $[counter(variables['version.MajorMinor'], 0)]
versionNumber: '$(version.MajorMinor).$(version.Revision)'
steps:
- task: PowerShell@2
displayName: Set the name of the build (i.e. the Build.BuildNumber)
inputs:
targetType: 'inline'
script: |
$doy = (Get-Date).DayofYear
Write-Host "##vso[task.setvariable variable=DayOfYear]$doy"
$rev = $env:BUILD_BUILDNUMBER.Split('.')[-1]
Write-Host "##vso[task.setvariable variable=Revision]$rev
Write-Host "set Revision to $rev"
[string] $buildName = "$(versionNumber).$doy.$rev"
Write-Host "Setting the name of the build to '$buildName'."
Write-Host "##vso[build.updatebuildnumber]$buildName"
这确实会生成一个版本号 (1.26.199.50),但是当我收到 MSBuild 任务时:
task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site" /p:Version=$(buildName)'
我收到版本错误。我什至尝试用 1.0.199.50 替换版本,但我得到了同样的错误。我知道每个段都必须小于 65534,因为这是 UInt 的最大值,所以我不明白为什么它会失败。
经过多次挫折后,我改为在发布管道中使用 Powershell 脚本来完成此操作。我有一个包含以下内容的 Powershell 任务,该任务位于文件转换任务之前。让它工作的步骤。
添加一个名为“MajorVersion”的发布管道变量。这是版本字符串的第一部分
添加一个 属性 到 appsettings.json 称为 AppConfig.Version,将其设置为任何本地测试。
添加一个 powershell 任务。顺序应该是 Powershell Task->File Transform->App Service Deploy:
$doy = $(Get-Date).DayofYear
[字符串] $buildName = "$Env:MajorVersion.$doy.$Env:BUILD_BUILDNUMBER"
写入主机“##vso[task.setvariable variable=AppConfig.Version;]$buildName
使用您喜欢的方法从您的应用设置访问变量。在核心中,可能通过 Configuration.GetSection("blah")
该程序集未标记版本,但您可以获取它以在 UI 上显示。我觉得这需要由 MS 简化,因为自动递增版本应该不那么困难。
我正在尝试为使用 Azure Pipelines 构建的 ASP.NET Core 3.1 Web 应用程序设置一个自动递增的版本号。我已经尝试了各种片段和管道任务,并尽可能生成版本号,但我的构建失败并显示消息
指定的版本字符串不符合要求的格式 - major[.minor[.build[.revision]
我正在使用以下 yml 片段生成版本号:
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
version.MajorMinor: '1' # Manually adjust the version number as needed for semantic versioning. Revision is auto-incremented.
version.Revision: $[counter(variables['version.MajorMinor'], 0)]
versionNumber: '$(version.MajorMinor).$(version.Revision)'
steps:
- task: PowerShell@2
displayName: Set the name of the build (i.e. the Build.BuildNumber)
inputs:
targetType: 'inline'
script: |
$doy = (Get-Date).DayofYear
Write-Host "##vso[task.setvariable variable=DayOfYear]$doy"
$rev = $env:BUILD_BUILDNUMBER.Split('.')[-1]
Write-Host "##vso[task.setvariable variable=Revision]$rev
Write-Host "set Revision to $rev"
[string] $buildName = "$(versionNumber).$doy.$rev"
Write-Host "Setting the name of the build to '$buildName'."
Write-Host "##vso[build.updatebuildnumber]$buildName"
这确实会生成一个版本号 (1.26.199.50),但是当我收到 MSBuild 任务时:
task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site" /p:Version=$(buildName)'
我收到版本错误。我什至尝试用 1.0.199.50 替换版本,但我得到了同样的错误。我知道每个段都必须小于 65534,因为这是 UInt 的最大值,所以我不明白为什么它会失败。
经过多次挫折后,我改为在发布管道中使用 Powershell 脚本来完成此操作。我有一个包含以下内容的 Powershell 任务,该任务位于文件转换任务之前。让它工作的步骤。
添加一个名为“MajorVersion”的发布管道变量。这是版本字符串的第一部分
添加一个 属性 到 appsettings.json 称为 AppConfig.Version,将其设置为任何本地测试。
添加一个 powershell 任务。顺序应该是 Powershell Task->File Transform->App Service Deploy:
$doy = $(Get-Date).DayofYear [字符串] $buildName = "$Env:MajorVersion.$doy.$Env:BUILD_BUILDNUMBER" 写入主机“##vso[task.setvariable variable=AppConfig.Version;]$buildName
使用您喜欢的方法从您的应用设置访问变量。在核心中,可能通过
Configuration.GetSection("blah")
该程序集未标记版本,但您可以获取它以在 UI 上显示。我觉得这需要由 MS 简化,因为自动递增版本应该不那么困难。