azure-pipelinesversioningazure-pipelines-build-task

Different Assembly build numbers in Azure Pipeline via yaml


I am trying to create an Azure pipeline build, test, and deploy of nuget packages to an Azure feed to work. I have everything working except that I want the individual projects to have their own versioning numbers. I've searched all over, but can't seem to find anything that helps. Here's my requirements:

This is what I currently have for my yaml file:

trigger: 
  branches:
    include:
      - main
      - develop

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/App.Common.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    feedsToUse: 'config'
    nugetConfigPath: '.\nuget.config'
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:SkipInvalidConfigurations=true /p:Version=$(Build.BuildNumber)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@3
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*Tests.dll
      !**\*TestApp.dll
      !**\obj\**

- task: CopyFiles@2
  inputs:
    sourceFolder: '$(Build.SourcesDirectory)'
    contents: '**/$(BuildConfiguration)/**/?(*.nupkg|*.symbols.nupkg)'
    targetFolder: '$(Build.ArtifactStagingDirectory)'

- task: CmdLine@2
  displayName: 'List files'
  inputs:
    script: |
      tree $(Agent.WorkFolder)\1 /f

- task: NuGetAuthenticate@1
  displayName: 'NuGet Authenticate'

- task: NuGetCommand@2
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: 'REDACTED'

With this build I get these numbers: 20241027.1.0.0

I have tried setting the "name" at the top of the yaml file like so: name: '1.0.0.$(Rev:r)', which works in creating incremental builds like 1.0.0.1, 1.0.0.2, etc, but everything is a 1.0.0.

Any help would be greatly appreciated. Even if I have to add separate build steps for each package to version them differently.


Solution

  • After much trial and error, I found a combination of these mistakes in my yaml as well as changes I made:

     <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
          <PropertyGroup>
              <!--x.x.Days Since 1/1/2024-->
              <CustomBuildNumber>$([MSBuild]::Subtract($([System.Math]::Floor($([MSBuild]::Divide($([System.DateTimeOffset]::UtcNow.ToUnixTimeSeconds()), 86400)))),19723))</CustomBuildNumber>
              <!--Second In Current Day / 2-->
              <CustomRevisionNumber>$([MSBuild]::Divide($([MSBuild]::Modulo($([System.DateTimeOffset]::UtcNow.ToUnixTimeSeconds()), 86400)), 2))</CustomRevisionNumber>
          </PropertyGroup>
      </Project>
    

    And used these settings in my csproj:

    <Version>8.0.$(CustomBuildNumber).$(CustomRevisionNumber)</Version>
    

    And this in the netstandard2.0 package project:

    <PackageVersion>1.0.$(CustomBuildNumber).$(CustomRevisionNumber)</PackageVersion>