'How to use $(Rev:r) in VSTS build definition?

I have requirement that my build is generating abc.msi file through Private build agent.Now I have added the Powershell task to rename the abc.msi with abc_3.0.0$(Rev:r).msi but The Powershell task is failing.Please help me out how to achieve this.I would like to have the build name format like abc_3.0.0.1 ,abc_3.0.0.2,abc_3.0.0.3 ...and so on.It should keep increase the value of $(Rev:r) as the builds are getting increased.

The Powershell command which I am running is:

Rename-Item -Path "C:\Softwares\vsts-agent-win-x86-2.147.1\_work\1\s\src\abcSetup\Release\abc.msi" -NewName "C:\Softwares\vsts-agent-win-x86-2.147.1\_work\1\s\src\abcSetup\Release\abc_3.0.0.$(Rev:r).msi"

Error:

Rev:r : The term 'Rev:r' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Softwares\vsts-agent-win-x86-2.147.1_work_temp\fef4cc6a-e677-4a08-ab29-73c7c31da755.ps1:2 char:243 + ... ork\1\s\src\abcSetup\Release\abc_3.0.0.$(Rev:r).msi" + ~~~~~ + CategoryInfo : ObjectNotFound: (Rev:r:String) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : CommandNotFoundException

[error]PowerShell exited with code '1'.

[section]Finishing: Renaming the .MSI File



Solution 1:[1]

Value of $(Rev:r) can not be accessed within a task. It can only be accessed to define build number for ex:

name: $(Build.SourceBranchName)-$(releaseVersion)$(Rev:.r)
trigger:
 - main
pool:
 vmImage: ubuntu-latest

Here name is the variable used to define build number in Yaml pipelines. And releaseVersion is a custom variable defined in Pipelines->Library. Once we set this it can be accessed inside task as below:

- task: CmdLine@2
  inputs:
    script: >
      nuget pack ClassLibrary1/ClassLibrary1.csproj  
      -OutputDirectory $(Build.ArtifactStagingDirectory)
      -NonInteractive 
      -Properties Configuration=release
      -Version $(Build.BuildNumber)
      -Verbosity Detailed 
      -IncludeReferencedProjects

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1